Solved

Resume error

Posted on 2003-11-26
5
308 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 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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…

726 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