Solved

OnError in Delphi

Posted on 2001-06-15
8
993 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 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
Technology Partners: 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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

728 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