1% * -*- Mode: Prolog -*- */
    2
    3:- use_module(library(thread_pool)).    4
    5% This is a minimal test case to justify bypassing prolog_exception_hook.
    6% The main program runs exception-free if sections A & B are both commented out.
    7% With section A commented out but section B present, three exceptions are reported.
    8% With sections A & B both present, no exceptions are reported.
    9
   10:- dynamic prolog_exception_hook/4.   11
   12% Section A:
   13%user:prolog_exception_hook(error(existence_error(thread,_),context(system:thread_property/2,_)),_,_,_) :- !, fail.
   14%user:prolog_exception_hook('$aborted',_,_,_) :- !, fail.
   15
   16% Section B:
   17user:prolog_exception_hook(E,_,_,_) :-
   18	format("Exception: ~w~n",[E]),
   19        backtrace(99),
   20        !,
   21        fail.
   22
   23% Main program:
   24main :-
   25	thread_pool_create(my_pool,4,[]),
   26	thread_create_in_pool(my_pool,run_job(a,b,c),Thread,[]),
   27	thread_join(Thread,Status),
   28	format("Thread ~w finished with status ~w~n",[Thread,Status]).
   29
   30run_job(X,Y,Z) :-
   31	format("X=~w Y=~w Z=~w~n",[X,Y,Z])