?
Solved

Resume error

Posted on 2003-11-26
5
Medium Priority
?
311 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
[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
  • 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 400 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 800 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 800 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 800 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
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

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