10.46.3.4 Tests Expected to Raise Exceptions

Tests that are expected to raise exceptions may be specified using the option exception(Expected) or one of its equivalents, or by wrapping the test in on_exception/3 or catch/3. The following tests are equivalent:

     :- use_module(library(terms)).
     test(div01) :-
          on_exception(Excp, A is 1/0, true),
          subsumeschk(error(evaluation_error(zero_divisor),_), Excp).
     
     test(div02, [error(evaluation_error(zero_divisor))]) :-
          A is 1/0.
     
     test(div03, [error(evaluation_error(zero_divisor),_)]) :-
          A is 1/0.
     
     test(div04, [exception(error(evaluation_error(zero_divisor),_))]) :-
          A is 1/0.
     
     test(div05, [throws(error(evaluation_error(zero_divisor),_))]) :-
          A is 1/0.

Send feedback on this subject.