Smart pascal source code
type
Exception1 = class(Exception)
end;
type
Exception2 = class(Exception)
end;
{ main.pas }
Begin
procedure Baz(i: Integer);
begin
if i = 0 then
raise new Exception1('Error message 1')
else
raise new Exception2('Error message 2');
end;
procedure Bar(i: Integer);
begin
Baz(i);
end;
procedure Foo;
var
i: Integer;
begin
for i := 0 to 2 do
begin
try
Bar(i);
except
on E: Exception1 do
WriteLn(E.ClassName + ' caught');
end;
end;
end;
Foo;
{ <<< CONSOLE OUTPUTS >>>
Exception1 caught
}
function Test1: String;
begin
raise Exception.Create('TEST');
end;
procedure Test2;
begin
StrToInt(Test1);
end;
Test2; { Uncaught Object }
function Test2() {
parseInt(Test1(), 10);
};
function Test1() {
var Result = "";
throw Exception.Create($New(Exception), "TEST");
return Result
};
function Foo() {
var i = 0;
for (i = 0; i <= 2; i++) {
try {
Bar(i);
} catch ($e) {
if ($Is($e, Exception1)) {
var E = $W($e);
WriteLn((ClassName$1($ToClassType(E)) + " caught"))
} else
throw $e
}
}
};
function Bar(i$1) {
Baz(i$1);
};
function Baz(i$2) {
if (!i$2) {
throw Exception.Create($New(Exception1), "Error message 1");
} else {
throw Exception.Create($New(Exception2), "Error message 2");
}
};
Foo();
Test2();
/// Exception2 = class (Exception)
/// [line: 35, column: 6, file: uMain]
var Exception2 = {
$ClassName : "Exception2",
$Parent : Exception,
$Init : function ($) {
Exception.$Init($);
},
Destroy : Exception.Destroy
};
/// Exception1 = class (Exception)
/// [line: 34, column: 6, file: uMain]
var Exception1 = {
$ClassName : "Exception1",
$Parent : Exception,
$Init : function ($) {
Exception.$Init($);
},
Destroy : Exception.Destroy
};