Trying to understand catch and throw syntax

View: New views
2 Messages — Rating Filter:   Alert me  

Trying to understand catch and throw syntax

by Steve Prior :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

 From reading the manual section on ISO compliant Exception handling I'm trying
to understand how to use this in my code, so I wrote the following to try it out:

crashme :-
    catch(
           (
              throw(error(formal, context))
           ),
           E,
           (
              print_message(error, E),
              fail
           )
         ).



I expected some kind of message output, but what I got instead was:

2 ?- crashme.
ERROR: Unknown error term: formal
false.


Can someone clarify the syntax of how you might throw an error in pure Prolog code?


Steve


_______________________________________________
SWI-Prolog mailing list
SWI-Prolog@...
https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog

Re: Trying to understand catch and throw syntax

by Ulrich Neumerkel :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> I expected some kind of message output, but what I got instead was:

see library(error) for the kinds of errors foreseen by ISO.
_______________________________________________
SWI-Prolog mailing list
SWI-Prolog@...
https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog