?
Solved

OnError in Delphi

Posted on 2001-06-15
8
Medium Priority
?
1,007 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 200 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 200 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month14 days, 7 hours left to enroll

770 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