On Thu, 10 Dec 2020, Bart via fpc-devel wrote:

On Thu, Dec 10, 2020 at 7:34 AM Sven Barth via fpc-devel
<fpc-devel@lists.freepascal.org> wrote:

That is correct, because without the SysUtils unit (which declared the
Exception type) the RTL can't convert the triggered runtime error to an
exception type that can be caught inside the try ... except ... end block.

I would have expected that in that scenario (no sysutils) try..except
or try..finally should raise a compilation error then.
Since you teel the compiler to do things it cannot do?

No.

Sysutils is only needed to convert run-time errors to exceptions.

You can perfectly use exceptions without sysutils, but they can not descend
from Exception, but from TObject. That exception classes descend from Exception
is a convention, not a compiler-enforced rule.

If you change your code to this
  Except
    On O : TObject do
     Writeln('except block : ',O.ClassName)

You'll see there is no output, because there is no exception object.

The reason is as Sven surmised: the setjmp mechanism used on non-windows
platforms.

It would be Delphi incompatible of course ...

B.t.w. (cannot test now, am at work): does it catc exceptions if any
other used unit in the main program uses sysutils?
I.o.w.: is it enough if sysutils gets linked in, or must it be in the
unit/prgram that actually has the try..except/try..finally code in it?

It is enough that sysutils gets linked in.

I checked that, the program you sent does not have sysutils linked in.


Michael.
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to