Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Changing Exception Error Messages in Delphi

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

670 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