From e5ab41faf611c61878ad792cbaaf0294cd5715dd Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Thu, 1 Jul 2021 19:55:40 +0000 Subject: Add exceptions :) implement catch/3 and throw/1 --- example.pl | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'example.pl') diff --git a/example.pl b/example.pl index c2c8335..6633ff0 100644 --- a/example.pl +++ b/example.pl @@ -22,3 +22,16 @@ curly(A) :- A = {one,two,three}. tester(A, B) :- !, A = B. tester(A, B) :- true. + +thrower(_, 10). +thrower(_, 20). +thrower(inner, _) :- throw(number(30)). +thrower(outer, _) :- throw(hehe). +thrower(_, 100). + +throwtest(Type, L) :- + catch( + catch((thrower(Type, N), L=N), number(N), L=N), + Other, + L=outer_exception(Other) + ). -- cgit v1.2.3