Solved

OnError in Delphi

Posted on 2001-06-15
8
983 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

839 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