September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,23 +0,0 @@
|
|||
:- object(exceptions).
|
||||
|
||||
:- public(double/2).
|
||||
double(X, Y) :-
|
||||
catch(double_it(X,Y), Error, handler(Error, Y)).
|
||||
|
||||
handler(error(not_a_number(X), logtalk(This::double(X,Y), Sender)), Y) :-
|
||||
% try to fix the error and resume computation;
|
||||
% if not possible, rethrow the exception
|
||||
( catch(number_codes(Nx, X), _, fail) ->
|
||||
double_it(Nx, Y)
|
||||
; throw(error(not_a_number(X), logtalk(This::double(X,Y), Sender)))
|
||||
).
|
||||
|
||||
double_it(X, Y) :-
|
||||
( number(X) ->
|
||||
Y is 2*X
|
||||
; this(This),
|
||||
sender(Sender),
|
||||
throw(error(not_a_number(X), logtalk(This::double(X,Y), Sender)))
|
||||
).
|
||||
|
||||
:- end_object.
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
| ?- exceptions::double(1, Double).
|
||||
Double = 2
|
||||
yes
|
||||
|
||||
| ?- exceptions::double("1", Double).
|
||||
Double = 2
|
||||
yes
|
||||
|
||||
| ?- exceptions::double(a, Double).
|
||||
uncaught exception: error(not_a_number(a),logtalk(exceptions::double(a,_),user))
|
||||
Loading…
Add table
Add a link
Reference in a new issue