Solved

Resume error

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

777 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