Catch / throw example with custom error

Hi,

I am reading the throw/1 documentation and expected error term and can’t figure it out / get it to work. Could someone post a simple example how to handle a custom error via a corresponding catch and throw

… no idea how iso errors fit into this as well …

scanning the list of iso error types, none really fit to what the error means – its a semantic kind of error, specific to the algorithm i am working on.

any help would be much appreciate,d

Dan

btw, here is what i do and that doesnt work

p0(X) :-
 catch(p1(X), myError(Data), recover(Data)).

then somehwere later …

q(Y) :- 
  condition(Y),
  throw(myError(Y)).

when run, the throw gets me an "Unknown message myError(abc)

with ‘abc’ being the bound value to Y.

oh,

it looks like it actually worked … i misinterpreted the debug message

Dan

There are two related things.

  • Exceptions of the from error(Formal, Context) are special. If Context is left unbound the system will fill it with a stack trace if the exception is not caught and the system will try to start the debugger as ealy as possible in an interactive session.
  • Define rules for prolog:error_message//1 to print error/2 messages based on
    the first argument or prolog:message//1 to handle any exception term.
2 Likes