Solved

OnError in Delphi

Posted on 2001-06-15
8
964 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:rbarzallo
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 20

Expert Comment

by:Madshi
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now