home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
vp21beta.zip
/
AEXMPSRC.RAR
/
DELPHI
/
XCPTDEMO.PAS
< prev
Wrap
Pascal/Delphi Source File
|
2000-08-15
|
2KB
|
73 lines
{█▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█}
{█ █}
{█ Virtual Pascal Examples. Version 2.1. █}
{█ Exceptions demonstration example █}
{█ ─────────────────────────────────────────────────█}
{█ Copyright (C) 1996-2000 vpascal.com █}
{█ █}
{▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀}
program XcptDemo;
{&X+,Delphi+}
Uses
Crt, SysUtils;
type
EParameterError = class(Exception);
//
// Guarded GotoLine procedure that raises an exception for an invalid parameter
//
procedure gGotoLine( Line : Integer );
begin
If ( Line in [1..20] ) then
GotoXY( 1, Line )
else
raise EParameterError.CreateFmt( 'Invalid line number: %d', [Line] );
end;
//
// Test procedure, using gGotoLine
//
procedure TestLine( Line : Integer);
begin
try
gGotoLine( Line );
Write( Format( 'Now at Line %d ', [Line] ) );
except
on E:Exception do
begin
GotoXY( 1, 22 );
Writeln( 'Error : ',E.Message ); // Write error message
raise; // Re-raise the exception
end;
end;
end;
procedure Test;
begin
try
TestLine( 10 ); // OK
TestLine( 3 ); // OK
TestLine( -1 ); // Invalid; generates exception
except
on E:EParameterError do
// Handle invalid parameter case
Writeln( 'Parameter error in some call' );
else
// handle any other exception
Writeln( 'Unexpected exception occured' );
end;
end;
begin
ClrScr;
WriteLn('Virtual Pascal Exceptions Demo Version 2.1 (C) 1996-2000 vpascal.com');
Test;
end.