ref: 6b3d59a3256a292b582e4313325ca14154211671
parent: 1b73b6d1323c69c0086a41bf85a9b85003377a3b
author: Peter Mikkelsen <[email protected]>
date: Mon Jul 19 09:12:59 EDT 2021
Print errors better in the repl
--- a/repl.pl
+++ b/repl.pl
@@ -75,10 +75,57 @@
),
write_bindings(Bs).
+print_exception(error(E, _)) :-
+ write('Unhandled error:
+ '), % \n\t
+ print_error(E),
+ nl.
print_exception(E) :-
+ E \= error(_,_),
write('Unhandled exception: '),
write(E),
nl.
+
+print_error(instantiation_error) :-
+ write('instantiation error').
+print_error(type_error(ValidType, Culprit)) :-
+ write('type error, expected '),
+ write(ValidType),
+ write(': '),
+ write(Culprit).
+print_error(domain_error(ValidDomain, Culprit)) :-
+ write('domain error, expected '),
+ write(ValidDomain),
+ write(': '),
+ write(Culprit).
+print_error(existence_error(ObjectType, Culprit)) :-
+ write('existence error, '),
+ write(Culprit),
+ write(' is not an existing object of type: '),
+ write(ObjectType).
+print_error(permission_error(Operation, Type, Culprit)) :-
+ write('permission error, cannot '),
+ write(Operation),
+ write(' '),
+ write(Type),
+ write(': '),
+ write(Culprit).
+print_error(representation_error(Flag)) :-
+ write('representation error: '),
+ write(Flag).
+print_error(evaluation_error(Error)) :-
+ write('evaluation error: '),
+ write(Error).
+print_error(resource_error(Res)) :-
+ write('resource error: '),
+ write(Res).
+print_error(syntax_error(E)) :-
+ write('syntax error: '),
+ write(E).
+print_error(system_error) :-
+ write('system error').
+print_error(E) :-
+ write(E).
whitespace(' ').
whitespace(' ').