0

Suppose I have a broken program like this:

:- set_prolog_flag(verbose, silent).
:- initialization(main).

main :-
  not_valid(X),
  halt.
main :-
  halt(1).

When I run it, SWI-Prolog tries to recover by entering an interactive mode:

swipl ./test.pl
Warning: /home/foo/test.pl:4:
    Singleton variables: [X]
ERROR: /home/foo/test.pl:2: Initialization goal raised exception:
ERROR: main/0: Undefined procedure: not_valid/1
?- 

How can I make it crash instead?


swipl --version
SWI-Prolog version 7.6.4 for amd64
sdgfsdh
  • 33,689
  • 26
  • 132
  • 245
  • I think the answer is in https://stackoverflow.com/questions/34485686/current-predicate-1-does-not-work-with-dynamic – brebs Mar 03 '22 at 19:05

1 Answers1

0

You may wrap the call to your main procedure with catch/3 and do something upon getting an error.

For example:

:- initialization(catch(main, Err, handle_error(Err))).

handle_error(Err):-
  writeln(Err),
  writeln('halting...'),
  halt(2).
gusbro
  • 22,357
  • 35
  • 46