Solved

Changing Exception Error Messages in Delphi

Posted on 2009-05-12
5
286 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 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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses
Course of the Month6 days, 9 hours left to enroll

636 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