Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Changing Exception Error Messages in Delphi

Posted on 2009-05-12
5
Medium Priority
?
294 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 38

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 38

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 38

Accepted Solution

by:
Geert Gruwez earned 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Integration Management Part 2
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

926 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