I am working on a beginner's tutorial from 'Modern Object Pascal Introduction for Programmers' by Michalis Kamburelis. I am having difficulty getting the Try... Exception statement to work correctly. Preview the following code:
Program tutorial_02;
{$mode objfpc}{$H+}{$J-}
Uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes
{ add any units after this };
Var
sglTest: Single;
Procedure TestProc(Const MyNum: Integer);
Begin
WriteLn('MyNumber + 10 is: ', MyNum + 10);
End;
Function TestFunc(Const MyTxt: String): String;
Begin
Result := MyTxt + 'Strings are automatically managed';
End;
Begin
Try
Try
WriteLn(TestFunc('Note: '));
TestProc(5);
sglTest := 15 / 5; //Division using "/" always makes float result - use "div" for integer division...
WriteLn('MyNum is now:', sglTest); //Scientific notation...
WriteLn('MyNum is now: ', sglTest:1:2); //2 decimal places...
Except
On E: Exception Do
Begin
WriteLn('An error occurred!');
End;
End;
Finally
{$IFDEF WINDOWS}
ReadLn;
{$ENDIF}
End;
End.
The line "On E: Exception Do" produces the error {Error: Identifier not found "Exception"} when I attempt to compile the tutorial app. If I comment out this one line, the program runs perfectly.
Does anyone spot any thing I'm doing wrong in this simple example? Syntax error? Am I leaving out a unit required for exception handling?
Please help!
Thanks in advance!!