Solved

Changing Exception Error Messages in Delphi

Posted on 2009-05-12
5
273 Views
Last Modified: 2012-05-06
How to Handle an Exception Error message in Delphi and Change the Text of this Message

such as ('' is not a floating point value) , I would like this message to appear like this to my application users (Error in Floating point conversation)... etc
0
Comment
Question by:i7mad
  • 3
  • 2
5 Comments
 
LVL 36

Expert Comment

by:Geert Gruwez
ID: 24363567
first catch then reraise it

procedure Test;
begin
  try
    ShowMessage(FloatToStr(1/0));
  except
    on EZeroDivide, EDivByZero:
      Raise Exception.Create('Only dummies divide by zero !');
  end;
end;
0
 

Author Comment

by:i7mad
ID: 24363580


Geert_Gruwez:

  Thanks for your fast response.

  I want to handle it on Application level;

for example: I want to show My own message when EConvertError happen
0
 
LVL 36

Expert Comment

by:Geert Gruwez
ID: 24363589
or analyze the exception text first and then reraise ...

procedure Test;
var Msg: string;
begin
  try
    ShowMessage(FloatToStr(1/0));
  except
    on E: Exception do
    begin
      Msg := '';
      if Pos('is not a floating point value', E.Message) > 0 then
        Msg := 'Error in Floating point conversation';
      // if  and so on
      if Msg <> '' then
        Raise Exception.Create(Msg);
    end;
  end;
end;
0
 
LVL 36

Accepted Solution

by:
Geert Gruwez earned 500 total points
ID: 24363637
then you need to catch it at application level too
write your own exception handler:


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

procedure TForm1.AppExcept(Sender: TObject; E: Exception);
var Msg: string;
begin
  Msg := '';
  if Pos('is not a floating point value', E.Message) > 0 then
    Msg := 'Error in Floating point conversation';
  // if  and so on
  if Msg = '' then
    Msg := E.Message;
  MessageDlg(Msg, mtError, [mbOk], 0)
end;
0
 

Author Closing Comment

by:i7mad
ID: 31580488
Very Helpful;  Thanks alot.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

705 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

11 Experts available now in Live!

Get 1:1 Help Now