Woa! 12 years later some new ideas! Holy Cow. Following
the ideas of Python I have now a prototype where catch/3
only matches the head of the chained exception:
/* SWI-Prolog 9.1.4 */
?- call_cleanup(throw(foo), throw(bar)).
ERROR: Unhandled exception: Unknown message: foo
ERROR: Unhandled exception: Unknown message: bar
?- catch(call_cleanup(throw(foo), throw(bar)), E, true).
E = foo.
/* Jekejeke Prolog 1.5.6 */
?- call_cleanup(throw(foo), throw(bar)).
Unknown exception: foo
Unknown exception: bar
?- catch(call_cleanup(throw(foo), throw(bar)), E, true).
E = foo.
In case somebody wants to access the full chained
exception, one can still use sys_trap/3:
/* Jekejeke Prolog 1.5.6 */
?- sys_trap(call_cleanup(throw(foo), throw(bar)), E, true).
E = cause(foo, bar).
Maybe this is less comfortable than Python, since the
suggestion is two different catchers, catch/3 and sys_trap/3.
Whereas Python has always the same catcher, but different throwers.
As a bonus, all the setup_call_cleanup/3 test cases as per
WG17 N215 should now pass, even in the presence of exception
chaining, when they are written with the help of the new catch/3.
The test case report shows me now:
Ok Nok Predicate
26 0 call_cleanup/2
38 0 setup_call_cleanup/3
BTW: What is the Python Exception Chaining? Check this out: https://docs.python.org/3/tutorial/errors.html#exception-chaining
The thingy also works with the Logtalk idiom in Dogelog
Player. There I now have as well the following behaviour,
for the new once_cleanup/2:
/* Dogelog Player 1.0.4 */
?- once_cleanup(throw(foo), throw(bar)).
foo /* in red color */
bar /* in red color */
?- catch(once_cleanup(throw(foo), throw(bar)), E, true).
E = foo.
?- sys_trap(once_cleanup(throw(foo), throw(bar)), E, true).
E = cause(foo, bar).
Mostowski Collapse schrieb am Dienstag, 21. Februar 2023 um 21:15:20 UTC+1:
Woa! 12 years later some new ideas! Holy Cow. Following
the ideas of Python I have now a prototype where catch/3
only matches the head of the chained exception:
/* SWI-Prolog 9.1.4 */
?- call_cleanup(throw(foo), throw(bar)).
ERROR: Unhandled exception: Unknown message: foo
ERROR: Unhandled exception: Unknown message: bar
?- catch(call_cleanup(throw(foo), throw(bar)), E, true).
E = foo.
/* Jekejeke Prolog 1.5.6 */
?- call_cleanup(throw(foo), throw(bar)).
Unknown exception: foo
Unknown exception: bar
?- catch(call_cleanup(throw(foo), throw(bar)), E, true).
E = foo.
In case somebody wants to access the full chained
exception, one can still use sys_trap/3:
/* Jekejeke Prolog 1.5.6 */
?- sys_trap(call_cleanup(throw(foo), throw(bar)), E, true).
E = cause(foo, bar).
Maybe this is less comfortable than Python, since the
suggestion is two different catchers, catch/3 and sys_trap/3.
Whereas Python has always the same catcher, but different throwers.
Ha Ha, Dogelog Player has thrown the cutter overboard,
but keeps the exception chaining, at least for the Logtalk idiom.
Mostowski Collapse schrieb am Dienstag, 21. Februar 2023 um 21:20:12 UTC+1:
As a bonus, all the setup_call_cleanup/3 test cases as per
WG17 N215 should now pass, even in the presence of exception
chaining, when they are written with the help of the new catch/3.
The test case report shows me now:
Ok Nok Predicate
26 0 call_cleanup/2
38 0 setup_call_cleanup/3
BTW: What is the Python Exception Chaining? Check this out: https://docs.python.org/3/tutorial/errors.html#exception-chaining
The thingy also works with the Logtalk idiom in Dogelog
Player. There I now have as well the following behaviour,
for the new once_cleanup/2:
/* Dogelog Player 1.0.4 */
?- once_cleanup(throw(foo), throw(bar)).
foo /* in red color */
bar /* in red color */
?- catch(once_cleanup(throw(foo), throw(bar)), E, true).
E = foo.
?- sys_trap(once_cleanup(throw(foo), throw(bar)), E, true).
E = cause(foo, bar).
Mostowski Collapse schrieb am Dienstag, 21. Februar 2023 um 21:15:20 UTC+1:
Woa! 12 years later some new ideas! Holy Cow. Following
the ideas of Python I have now a prototype where catch/3
only matches the head of the chained exception:
/* SWI-Prolog 9.1.4 */
?- call_cleanup(throw(foo), throw(bar)).
ERROR: Unhandled exception: Unknown message: foo
ERROR: Unhandled exception: Unknown message: bar
?- catch(call_cleanup(throw(foo), throw(bar)), E, true).
E = foo.
/* Jekejeke Prolog 1.5.6 */
?- call_cleanup(throw(foo), throw(bar)).
Unknown exception: foo
Unknown exception: bar
?- catch(call_cleanup(throw(foo), throw(bar)), E, true).
E = foo.
In case somebody wants to access the full chained
exception, one can still use sys_trap/3:
/* Jekejeke Prolog 1.5.6 */
?- sys_trap(call_cleanup(throw(foo), throw(bar)), E, true).
E = cause(foo, bar).
Maybe this is less comfortable than Python, since the
suggestion is two different catchers, catch/3 and sys_trap/3.
Whereas Python has always the same catcher, but different throwers.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 492 |
Nodes: | 16 (3 / 13) |
Uptime: | 147:51:30 |
Calls: | 9,697 |
Calls today: | 7 |
Files: | 13,732 |
Messages: | 6,178,740 |