Solved

Resume error

Posted on 2003-11-26
5
303 Views
Last Modified: 2012-05-04
How can we avoid to appear the message dialog box error? Is there any way with Try except on...? The object is to resume this box without the user to notice it. Anyway can we put this error in a Variable?
Thanks,
Luis
0
Comment
Question by:lfgmartins
  • 2
  • 2
5 Comments
 
LVL 9

Expert Comment

by:mocarts
ID: 9824078
hi, Luis :)
You can use TApplicationEvents component (located on Additional component palette page) and define OnException event to provide custom behaviour when unhandled exception occurs.
See Delphi help for detailed description and example.

wbr, mo.
0
 
LVL 9

Assisted Solution

by:mocarts
mocarts earned 100 total points
ID: 9824108
addition: you can define your OnException event handler even without TApplicationEvents component by directly assigning your custom event handler to Application global variables OnException property (Application variable for standard applications resides in Forms.pas unit):

uses ...Forms;
type
  TForm1 = class(TForm)
  ..
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    procedure MyExceptionHandler(Sender: TObject; E: Exception);
  end;

implementation

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

procedure TForm1.FormDestroy(Sender: TObject);
begin
  Application.OnException := MyExceptionHandler
end;

procedure TForm1.MyExceptionHandler(Sender: TObject; E: Exception);
begin
  LogToFile(DateTimeToStr(Now) +': '+ E.Message);
end;
0
 
LVL 5

Assisted Solution

by:Darth_helge
Darth_helge earned 200 total points
ID: 9824497
maybe I'm totally wrong here, but.. u want the program to ignore the error?
use an empty try..except block.

procedure TForm1.Button1Click(Sender: TObject);
var
Q: TADOQuery;
begin
 try
 showmessage(Q.Fields[0].AsString);
 except
 end;
 showmessage('program resumed');
end;

normally the showmessage(Q.fields[0].asString) would have produced a "list index out of bounds error", but with inside an empty try..except it just resumes the program and writes the showmessagebox beneath..
0
 
LVL 17

Accepted Solution

by:
geobul earned 200 total points
ID: 9826076
Just my 2 cents:
If you are running your app from inside the Delphi IDE there will be an error box (or uncheck 'Stop on Delphi Exceptions' checkbox in Tools-Debugger Options-Language Exceptions tab). But if you're running your app as usual exe and have used try
  ..
except
end;

then there won't be an error.

Regards, Geo
0
 
LVL 17

Assisted Solution

by:geobul
geobul earned 200 total points
ID: 9826144
About saving errors: another way

procedure TForm1.Button1Click(Sender: TObject);
var
  sError: string;
  i: integer;
begin
  sError := '';
  try
    i := StrToInt('asdf');
  except
    on E: Exception do sError := E.Message;
  end;
  if sError <> '' then begin
    ShowMessage(sError);
    sError := '';
  end;
  ....
end;

Regards, Geo
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
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 Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

896 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

15 Experts available now in Live!

Get 1:1 Help Now