]> Repositorios git - scryer-prolog.git/commit
Add g_caused_exception/2 for custom toplevel error handling
authorJ.J. Tolton <[email protected]>
Sat, 8 Nov 2025 17:43:46 +0000 (12:43 -0500)
committerJ.J. Tolton <[email protected]>
Sun, 9 Nov 2025 17:44:48 +0000 (12:44 -0500)
commit617a551a56b3cc1f90c4c52ec2f215cf6b066cb6
tree5b30310d112cfacd8b57c3db750f6ce902ba0e17
parent31247545c3331ffff00368802f1e36abd4735c99
Add g_caused_exception/2 for custom toplevel error handling

When a goal throws an exception during initialization (-g flag), the
system now asserts g_caused_exception(Goal, Exception) in the user
module. This allows custom toplevels (-t flag) to check if an error
occurred and handle it appropriately.

Example usage:
  scryer-prolog -g "throw(error)" -t check_error

Where check_error can be:
  :- dynamic(g_caused_exception/2).

  check_error :-
      (   g_caused_exception(_, E) ->
          write('Error: '), write(E), nl, halt(1)
      ;   halt(0)
      ).

This enables scripts to use custom toplevels for sophisticated error
handling and exit code logic.

Addresses: https://github.com/mthom/scryer-prolog/pull/3147#issuecomment-3503875719

Co-Authored-By: J.J.'s Robot <[email protected]>
src/toplevel.pl