Recent

Author Topic: How to Show the name of the exception  (Read 3736 times)

BlueIcaro

  • Hero Member
  • *****
  • Posts: 818
    • Blog personal
How to Show the name of the exception
« on: January 12, 2011, 06:22:26 pm »
Hello, I making some test with exceptions
I did this test program
Code: Pascal  [Select][+][-]
  1.  
  2. unit Unit1 ;
  3.  
  4. {$mode objfpc}{$H+}
  5.  
  6. interface
  7.  
  8. uses
  9.   Classes ,SysUtils ,FileUtil ,Forms ,Controls ,Graphics ,Dialogs ,StdCtrls ;
  10.  
  11. Type MiError = Class (Exception);
  12.  
  13. type
  14.  
  15.   { TForm1 }
  16.  
  17.   TForm1 = class(TForm )
  18.     Button1 :TButton ;
  19.     Edit1 :TEdit ;
  20.     procedure Button1Click (Sender :TObject );
  21.   private
  22.     { private declarations }
  23.   Procedure MiPrueba;
  24.   public
  25.     { public declarations }
  26.   end;
  27.  
  28. var
  29.   Form1 : TForm1 ;
  30.  
  31. implementation
  32.  
  33. {$R *.lfm}
  34.  
  35. { TForm1 }
  36.  
  37. procedure TForm1 .Button1Click (Sender :TObject );
  38. begin
  39.  Try
  40.    MiPrueba;
  41.  Except
  42.    On MiError do
  43.    ShowMessage ('Error mio');
  44.    Else
  45.  
  46.    ShowMessage (Exception.Message); //Show the "generic" exception
  47.  end;
  48. end;
  49.  
  50. procedure TForm1 .MiPrueba ;
  51. begin
  52.    IF (StrToInt (Edit1.Text)) = 1 Then
  53.   Begin
  54.     Raise MiError.Create('Mi Error');
  55.   end;
  56. end;
  57.  
  58. end.
  59.            
  60.  
  61.  

Well, I want to show the name of the "generic" exception, where I have the showMessage

Thanks

/BlueIcaro

Leledumbo

  • Hero Member
  • *****
  • Posts: 8799
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: How to Show the name of the exception
« Reply #1 on: January 12, 2011, 07:16:17 pm »
Code: Delphi  [Select][+][-]
  1. try
  2.   .. // something bad
  3. except
  4.   on e: Exception do
  5.     ShowMessage(e.ClassName);
  6. end;
  7.  

BlueIcaro

  • Hero Member
  • *****
  • Posts: 818
    • Blog personal
Re: How to Show the name of the exception
« Reply #2 on: January 12, 2011, 08:30:02 pm »
Thank you, Leledumbo, it's works  :)

/BlueIcaro

 

TinyPortal © 2005-2018