Discussion:
[fpc-devel] Exceptions on wiki
Kirinn
2018-08-01 00:32:14 UTC
Permalink
Hi all,

Inspired by Gareth aka. Kit's infectious enthusiasm, and the recent long
discussion on exceptions on this list, I wrote up an article on
Exceptions on the FPC wiki. (Strangely enough we didn't have one before.)

http://wiki.freepascal.org/Exceptions

I hope it'll be useful, and not entirely inaccurate! Particularly the
part about performance. If a programmer knows exactly what each
exception statement inserts in the code, that should help in deciding
when to worry about the performance, and when to embrace the convenience.

~Kirinn

_______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/c
J. Gareth Moreton
2018-08-01 21:04:24 UTC
Permalink
Infectious enthusiasm - I like that! I'm honoured.

It's a good start on the Wiki article.  For more advanced things, you
might want to mention how you can use "raise" to re-raise an exception in
an except block, and the fact that SysUtils has code that wraps interrupts
like SIGSEGV and SIGFPE onto exception objects.

Gareth aka. Kit

On Wed 01/08/18 01:32 , Kirinn ***@mooncore.eu sent:
Hi all,

Inspired by Gareth aka. Kit's infectious enthusiasm, and the recent long
discussion on exceptions on this list, I wrote up an article on
Exceptions on the FPC wiki. (Strangely enough we didn't have one before.)

http://wiki.freepascal.org/Exceptions
[1]">http://wiki.freepascal.org/Exceptions

I hope it'll be useful, and not entirely inaccurate! Particularly the
part about performance. If a programmer knows exactly what each
exception statement inserts in the code, that should help in deciding
when to worry about the performance, and when to embrace the convenience.

~Kirinn

_______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org [2]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
[3]">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel



Links:
Paul Breneman
2018-08-01 22:24:43 UTC
Permalink
Post by Kirinn
Hi all,
Inspired by Gareth aka. Kit's infectious enthusiasm, and the recent long
discussion on exceptions on this list, I wrote up an article on
Exceptions on the FPC wiki. (Strangely enough we didn't have one before.)
http://wiki.freepascal.org/Exceptions
I hope it'll be useful, and not entirely inaccurate! Particularly the
part about performance. If a programmer knows exactly what each
exception statement inserts in the code, that should help in deciding
when to worry about the performance, and when to embrace the convenience.
~Kirinn
Thanks Kirinn for making this new wiki page. I just added a single line
at the bottom for "Further reading".

When you add a component to your program, are you made aware about all
of the exceptions that might be raised by the component? When writing
control software this can be *very* important.

There is a little more to the old story here (maybe should be added to
the wiki page):
https://community.embarcadero.com/blogs/entry/delphi-s-involvement-with-the-esa-rosetta-comet-spacecraft-project-1

I have these links here:
http://turbocontrol.com/embeddedfreepascal.htm

Best regards,
Paul
www.ControlPascal.com
_______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.o
Sven Barth via fpc-devel
2018-08-02 05:54:35 UTC
Permalink
Post by Kirinn
Hi all,
Inspired by Gareth aka. Kit's infectious enthusiasm, and the recent long
discussion on exceptions on this list, I wrote up an article on
Exceptions on the FPC wiki. (Strangely enough we didn't have one before.)
http://wiki.freepascal.org/Exceptions
I hope it'll be useful, and not entirely inaccurate! Particularly the
part about performance. If a programmer knows exactly what each
exception statement inserts in the code, that should help in deciding
when to worry about the performance, and when to embrace the convenience.
Please note that you can't generalize the performance impact as it depends
on the used exception handling mechanism. By default FPC uses
setjmp/longjmp which exhibit the behavior you described. On Win64 however
SEH is used which - in that platform - relies on metadata inside the binary
to mark the areas for a protected block (no matter whether it's for
"except" or "finally"). On Win32 with SEH enabled (which isn't the default
currently) it is again different. And should we decide to support DWARF
exception frames that would again be different.

Regards,
Sven
Joost van der Sluis
2018-08-02 13:11:26 UTC
Permalink
Post by Kirinn
Inspired by Gareth aka. Kit's infectious enthusiasm, and the recent long
discussion on exceptions on this list, I wrote up an article on
Exceptions on the FPC wiki. (Strangely enough we didn't have one before.)
http://wiki.freepascal.org/Exceptions
We had some discussion about memory-leaks and exceptions. All condensed
into this bug report: https://bugs.freepascal.org/view.php?id=33650

Maybe something to add?

Regards,

Joost.
_______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailm
J. Gareth Moreton
2018-08-02 17:13:35 UTC
Permalink
The information in the Wiki about how exception frames are set up is
pretty nice. I didn't know that 'raise' creates an exception frame for the
procedure it appears in, but explains why it's often shipped off to another
local procedure. Very useful information!
True though, it's hard to generalise the performance impact of exception
handlers and try...finally blocks, although I think the simple rule of
thumb is that there is a performance hit no matter what you try.

Gareth aka. Kit

On Thu 02/08/18 06:54 , Sven Barth via fpc-devel
fpc-***@lists.freepascal.org sent:
Kirinn schrieb am Mi., 1. Aug. 2018, 23:30:
Hi all,

Inspired by Gareth aka. Kit's infectious enthusiasm, and the recent long
discussion on exceptions on this list, I wrote up an article on
Exceptions on the FPC wiki. (Strangely enough we didn't have one before.)

http://wiki.freepascal.org/Exceptions [2]

I hope it'll be useful, and not entirely inaccurate! Particularly the
part about performance. If a programmer knows exactly what each
exception statement inserts in the code, that should help in deciding
when to worry about the performance, and when to embrace the convenience.

Please note that you can't generalize the performance impact as it depends
on the used exception handling mechanism. By default FPC uses
setjmp/longjmp which exhibit the behavior you described. On Win64 however
SEH is used which - in that platform - relies on metadata inside the binary
to mark the areas for a protected block (no matter whether it's for
"except" or "finally"). On Win32 with SEH enabled (which isn't the default
currently) it is again different. And should we decide to support DWARF
exception frames that would again be different. 
Regards, Sven  _______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org [3]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
[4]">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel



Links:
Sergei Gorelkin via fpc-devel
2018-08-02 19:00:28 UTC
Permalink
The information in the Wiki about how exception frames are set up is pretty nice. I didn't know that
'raise' creates an exception frame for the procedure it appears in, but explains why it's often
shipped off to another local procedure. Very useful information!
Implicit exception frames in procedures with 'raise' clause come from string manipulations that are
used to compose non-trivial exception messages, not from the 'raise' itself.

Regards,
Sergei
True though, it's hard to generalise the performance impact of exception handlers and try...finally
blocks, although I think the simple rule of thumb is that there is a performance hit no matter what
you try.
Gareth aka. Kit
Hi all,
Inspired by Gareth aka. Kit's infectious enthusiasm, and the recent long
discussion on exceptions on this list, I wrote up an article on
Exceptions on the FPC wiki. (Strangely enough we didn't have one before.)
http://wiki.freepascal.org/Exceptions
I hope it'll be useful, and not entirely inaccurate! Particularly the
part about performance. If a programmer knows exactly what each
exception statement inserts in the code, that should help in deciding
when to worry about the performance, and when to embrace the convenience.
Please note that you can't generalize the performance impact as it depends on the used exception
handling mechanism. By default FPC uses setjmp/longjmp which exhibit the behavior you described.
On Win64 however SEH is used which - in that platform - relies on metadata inside the binary to
mark the areas for a protected block (no matter whether it's for "except" or "finally"). On
Win32 with SEH enabled (which isn't the default currently) it is again different. And should we
decide to support DWARF exception frames that would again be different.
Regards,
Sven
_______________________________________________
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel <<a
href=>">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
_______________________________________________
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
_______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/f

Loading...