home *** CD-ROM | disk | FTP | other *** search
/ Delphi 4 Bible / Delphi_4_Bible_Tom_Swan_IDG_Books_1998.iso / source / EXCEPT3 / MAIN.PAS < prev    next >
Pascal/Delphi Source File  |  1998-04-13  |  1KB  |  54 lines

  1. unit Main;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, Windows, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls;
  8.  
  9. type
  10.   TMainForm = class(TForm)
  11.     Label1: TLabel;
  12.     Edit1: TEdit;
  13.     Label2: TLabel;
  14.     Button1: TButton;
  15.     procedure Button1Click(Sender: TObject);
  16.   private
  17.     { Private declarations }
  18.   public
  19.     { Public declarations }
  20.   end;
  21.  
  22. var
  23.   MainForm: TMainForm;
  24.  
  25. implementation
  26.  
  27. {$R *.DFM}
  28.  
  29. procedure TMainForm.Button1Click(Sender: TObject);
  30. var
  31.   N: Integer; S: String;
  32.   // Nested exception handler
  33.   procedure Handler(Message: String);
  34.   begin
  35.     ShowMessage(Message + ' Try again.');
  36.     Edit1.SetFocus;
  37.   end;
  38. begin
  39.   try
  40.     N := StrToInt(Edit1.Text);
  41.     if (N < 0) or (N > 99) then
  42.       raise ERangeError.Create('Value out of range!')
  43.     else begin
  44.       ShowMessage('Success! Click Ok to end program');
  45.       Close;
  46.     end;
  47.   except
  48.     on E: EIntError do Handler(E.Message);
  49.     on E: EConvertError do Handler(E.Message);
  50.   end;
  51. end;
  52.  
  53. end.
  54.