Hi Gambit List,
I'd like to have some functionality in gambit similar to 'finally' blocks in java/python where a block of code is always executed regardless of any exceptions thrown.
I'm currently using an exception handler that catches the exception and re-raises it after doing the cleanup stuff, but this loses the original 'where the exception was raised from' metadata. Is there a better way? (or a better idiom for resource cleanup that I should be using?)
Thanks,
Phil
Afficher les réponses par date
What you're looking for is called dynamic-wind. It is even more generic than Java's try/catch/finally idiom and surprisingly it is not even a special form but a simple plain function.
Phil Dawes wrote:
Hi Gambit List,
I'd like to have some functionality in gambit similar to 'finally' blocks in java/python where a block of code is always executed regardless of any exceptions thrown.
I'm currently using an exception handler that catches the exception and re-raises it after doing the cleanup stuff, but this loses the original 'where the exception was raised from' metadata. Is there a better way? (or a better idiom for resource cleanup that I should be using?)
Thanks,
Phil
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 27-Jan-07, at 1:36 PM, Phil Dawes wrote:
Hi Gambit List,
I'd like to have some functionality in gambit similar to 'finally' blocks in java/python where a block of code is always executed regardless of any exceptions thrown.
I'm currently using an exception handler that catches the exception and re-raises it after doing the cleanup stuff, but this loses the original 'where the exception was raised from' metadata.
I'm not sure I understand what you mean by that (i.e. 'where the exception was raised from' metadata).
When an exception is raised the continuation of the exception handler is identical to the continuation of the primitive that raised the exception. On the other hand, when you use with-exception-catcher or dynamic-wind, the continuation will be unwound, so you lose the continuation of the primitive. So, if you want to preserve this information, you could use call/cc (or ##continuation-capture) to save the information for later use.
Marc
Hi Marc,
Apologies - "'where the exception was raised from' metadata" isn't exactly clear!
I was after preserving the original line number in the exception output when it propagates to the top of the stack and gets printed in the repl. It turns out that 'dynamic-wind' appears to do exactly what I want (i.e. the 'after' block gets executed if an exception is thrown or not - correct?).
Thanks again,
Phil
Marc Feeley wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 27-Jan-07, at 1:36 PM, Phil Dawes wrote:
Hi Gambit List,
I'd like to have some functionality in gambit similar to 'finally' blocks in java/python where a block of code is always executed regardless of any exceptions thrown.
I'm currently using an exception handler that catches the exception and re-raises it after doing the cleanup stuff, but this loses the original 'where the exception was raised from' metadata.
I'm not sure I understand what you mean by that (i.e. 'where the exception was raised from' metadata).
When an exception is raised the continuation of the exception handler is identical to the continuation of the primitive that raised the exception. On the other hand, when you use with-exception-catcher or dynamic-wind, the continuation will be unwound, so you lose the continuation of the primitive. So, if you want to preserve this information, you could use call/cc (or ##continuation-capture) to save the information for later use.
Marc
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.3 (Darwin)
iD8DBQFFvWkq//V9Zc2T/v4RAre1AJ9VzzafTQMdULKgLtRZIAadj9D9RwCdGyLw /MLFr6D6n0no71JPxAKnQ+U= =Y8hK -----END PGP SIGNATURE-----