[fpc-pascal]'try-except'-problem

Michael.VanCanneyt at Wisa.be Michael.VanCanneyt at Wisa.be
Fri Sep 15 23:11:24 CEST 2000


On Fri, 15 Sep 2000, Dominik Schulz wrote:

> Hi!
> 
> I'm new to Free Pascal an Object Pascal. So I tried the following
> program:
> -----------------------
> program testtry;
> {$mode objfpc}
> {$I-} //I'm not really sure whether this switch is usefull here.
> uses crt;
> 
> var a, b : word;
> 
> begin
>   writeln('start');
>   a :=  1;
>   b :=  a - 1;
>   try
>     a := 1 div b;
>   except
>     writeln('Error');
>   end;
> 
>   writeln('end');
> end.
> -----------------------
> 
> This program always crashes with RE 200.
> Why doesn't the try-except-block avoid this?

Because you must use sysutils; if you don't use sysutils, then the RTE
is not converted to an exception, and so the try..except block is not 
useful.

so all you need to do is add 'sysutils' to the uses clause.

This is the same behaviour as Delphi, BTW.

Michael.





More information about the fpc-pascal mailing list