Solved

OnError in Delphi

Posted on 2001-06-15
8
977 Views
Last Modified: 2008-02-01
Exists some way to determine and to control (aside from try) the error that causes that an application is cancelled?
Something similar to the OnError de Visual BASIC exists, I I am using Delphi 5.
Greetings Ruben
0
Comment
Question by:rbarzallo
8 Comments
 
LVL 7

Expert Comment

by:Motaz
ID: 6197517
use try except:

try
  AssignFile(F, 'test.file');
  Reset(F);
  Writeln(F, 'test');
  CloseFile(F);
except
on e: exception do
  ShowMessage(E.Message);
end; // try

// Program execution will resume normally
0
 
LVL 17

Accepted Solution

by:
inthe earned 50 total points
ID: 6197564
hi,
another way if your trying to catch a particular exception you can use the application.onexception event:
many of the "e" exceptions are in sysutils and the db units.

  private
    { Private declarations }
procedure MyExceptionHandler(Sender: TObject; E :Exception);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}
procedure TForm1.MyExceptionHandler(Sender: TObject; E :Exception);
begin
  if E is EOutOfMemory then
   begin
   showmessage('EOutOfMemory');
   end
    else
   if E is EInOutError then
   begin
   showmessage('EInOutError');
   end
    else
   if E is EDivByZero then
   begin
   showmessage('EDivByZero');
   end
    else
   if E is EAbort then
   begin
   showmessage('EAbort');
   end;
//following is to to catch any other errors
   Application.showException( E);
  end;

procedure TForm1.FormCreate(Sender: TObject);
 begin
  Application.onException := MyExceptionHandler;
 end;

end.
0
 
LVL 20

Assisted Solution

by:Madshi
Madshi earned 50 total points
ID: 6197654
You might also want to look at my exception handling package (free for non-commercial usage):

http://help.madshi.net/Data/madExcept.htm

Regards, Madshi.
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Author Comment

by:rbarzallo
ID: 6198441
Thanks for their aid, but really what I need are something that allows me to control the exceptions that appear within a task, I that I can place try..except in each place that I believe that it is going away to present/display a problem but it must have another solution.

Madshi,

what I understand or I am mistaken, its application madexcept does not report errors within tasks?




0
 
LVL 20

Expert Comment

by:Madshi
ID: 6198776
madExcept shows exceptions that occur in your program and that are NOT catched by "try..except" blocks. Normally in such a case you get a short box like "error blabla at address $12345678". With madExcept the box get much more detailed.
Furthermore you can register your own exception handlers, that e.g. don't show the box but instead send the exception to you via email or something like that.
Basically you can do something similar (I mean don't show the box, but send the exception via mail) without madExcept, too (by using Application.OnException), but madExcept catches some more exceptions, that doesn't run through Application.OnException. Furthermore with madExcept you have much more detailed exception information.

If I understand you correctly, you should either go with Application.OnException or with madExcept.RegisterExceptionHandler.

Regards, Madshi.
0
 

Author Comment

by:rbarzallo
ID: 6204913
The routine this very good and works correctly. The additional question is:
The program A main executes a task that is in another program B, since I can make so that program B, when error detects algun takes exception from program A.
Greetings Ruben
0
 

Author Comment

by:rbarzallo
ID: 6204914
The routine this very good and works correctly. The additional question is:
The program A main executes a task that is in another program B, since I can make so that program B, when error detects algun takes exception from program A.
Greetings Ruben
0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 9285941
rbarzallo,
No comment has been added lately (808 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: split points between inthe http:#6197564 and madshi

Please leave any comments here within 7 days.

-- Please DO NOT accept this comment as an answer ! --

Thanks,

DragonSlayer
EE Cleanup Volunteer
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question