Solved

Changing Exception Error Messages in Delphi

Posted on 2009-05-12
5
285 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
[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
  • 3
  • 2
5 Comments
 
LVL 37

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 37

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 37

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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 use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 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