mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-22 12:53:47 +00:00
Estimated hours taken: 8 Move exception handling into the standard library, and change error/1 so that it throws an exception. This has two advantages: one is that user code can now catch exceptions caused by calls to error/1, the other is that the debugger handles calls to error/1 more gracefully (by virtue of its existing support for exception handling). extras/exceptions/exception.m: library/exception.m: Move exception.m from `extras' into the standard library. Change the code for handling uncaught exceptions so that it prints out the same diagnostics that error/1 used to print out (i.e. a stack trace and the last debugger event number). extras/exceptions/Mmakefile: extras/exceptions/test_exceptions.exp: extras/exceptions/test_exceptions.m: extras/exceptions/test_exceptions_func.exp: extras/exceptions/test_exceptions_func.m: extras/exceptions/test_uncaught_exception.exp: extras/exceptions/test_uncaught_exception.m tests/hard_coded/exceptions/Mmakefile: tests/hard_coded/exceptions/test_exceptions.exp: tests/hard_coded/exceptions/test_exceptions.m: tests/hard_coded/exceptions/test_exceptions_func.exp: tests/hard_coded/exceptions/test_exceptions_func.m: tests/hard_coded/exceptions/test_uncaught_exception.exp: tests/hard_coded/exceptions/test_uncaught_exception.exp2: tests/hard_coded/exceptions/test_uncaught_exception.m Move the exception test cases from extras/exceptions to a new directory tests/hard_coded/exceptions. Also, change the expected output for the `test_uncaught_exception' test case, since it now prints out more information. tests/hard_coded/Mmakefile: Add `exceptions' to the list of subdirectories. extras/exceptions/README: Delete this file, since the files that it refers to have now all been moved elsewhere. library/require.m: Change error/1 so that it throws an exception. library/library.m: Add exceptions.m to the list of modules in the standard library.
149 lines
5.0 KiB
Mathematica
149 lines
5.0 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% Copyright (C) 1997-1998 The University of Melbourne.
|
|
% This file may only be copied under the terms of the GNU Library General
|
|
% Public License - see the file COPYING.LIB in the Mercury distribution.
|
|
%---------------------------------------------------------------------------%
|
|
|
|
% File: test_exceptions.m.
|
|
% Main author: fjh.
|
|
|
|
% Test cases for exception handling.
|
|
|
|
% XXX we should test nested exception handlers.
|
|
% XXX we should also test exceptions with nested calls to solutions/2.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- module test_exceptions.
|
|
:- interface.
|
|
:- import_module io.
|
|
|
|
:- pred main(io__state::di, io__state::uo) is cc_multi.
|
|
|
|
:- implementation.
|
|
:- import_module std_util.
|
|
:- import_module exception.
|
|
|
|
main -->
|
|
{ try(det_throw, DetThrowResult) },
|
|
print("det_throw: "), print(DetThrowResult), nl,
|
|
{ try(det_succeed, DetSucceedResult) },
|
|
print("det_succeed: "), print(DetSucceedResult), nl,
|
|
|
|
{ try(semidet_throw, SemidetThrowResult) },
|
|
print("semidet_throw: "), print(SemidetThrowResult), nl,
|
|
|
|
{ try(semidet_succeed, SemidetSucceedResult) },
|
|
print("semidet_succeed: "), print(SemidetSucceedResult), nl,
|
|
|
|
{ try(semidet_fail, SemidetFailResult) },
|
|
print("semidet_fail: "), print(SemidetFailResult), nl,
|
|
|
|
{ try(cc_multi_throw, CCMultiThrowResult) },
|
|
print("cc_multi_throw: "), print(CCMultiThrowResult), nl,
|
|
{ try(cc_multi_succeed, CCMultiSucceedResult) },
|
|
print("cc_multi_succeed: "), print(CCMultiSucceedResult), nl,
|
|
|
|
{ try(cc_nondet_throw, CCNondetThrowResult) },
|
|
print("cc_nondet_throw: "), print(CCNondetThrowResult), nl,
|
|
|
|
{ try(cc_nondet_succeed, CCNondetSucceedResult) },
|
|
print("cc_nondet_succeed: "), print(CCNondetSucceedResult), nl,
|
|
|
|
{ try(cc_nondet_fail, CCNondetFailResult) },
|
|
print("cc_nondet_fail: "), print(CCNondetFailResult), nl,
|
|
|
|
{ try((pred(R::out) is det :- solutions(multi_throw, R)),
|
|
MultiThrowResult) },
|
|
print("multi_throw: "), print(MultiThrowResult), nl,
|
|
{ try((pred(R::out) is det :- solutions(multi_succeed, R)),
|
|
MultiSucceedResult) },
|
|
print("multi_succeed: "), print(MultiSucceedResult), nl,
|
|
{ try((pred(R::out) is det :-
|
|
solutions(multi_succeed_then_throw, R)),
|
|
MultiSucceedThenThrowResult) },
|
|
print("multi_succeed_then_throw: "),
|
|
print(MultiSucceedThenThrowResult), nl,
|
|
|
|
{ try((pred(R::out) is det :- solutions(nondet_throw, R)),
|
|
NondetThrowResult) },
|
|
print("nondet_throw: "), print(NondetThrowResult), nl,
|
|
{ try((pred(R::out) is det :- solutions(nondet_succeed, R)),
|
|
NondetSucceedResult) },
|
|
print("nondet_succeed: "), print(NondetSucceedResult), nl,
|
|
{ try((pred(R::out) is det :- solutions(nondet_fail, R)),
|
|
NondetFailResult) },
|
|
print("nondet_fail: "), print(NondetFailResult), nl,
|
|
{ try((pred(R::out) is det :-
|
|
solutions(nondet_succeed_then_throw, R)),
|
|
NondetSucceedThenThrowResult) },
|
|
print("nondet_succeed_then_throw: "),
|
|
print(NondetSucceedThenThrowResult), nl.
|
|
|
|
:- pred det_throw(string::out) is det.
|
|
det_throw(_) :- throw("det_throw").
|
|
|
|
:- pred semidet_throw(string::out) is semidet.
|
|
semidet_throw(_) :- throw("semidet_throw").
|
|
|
|
:- pred nondet_throw(string::out) is nondet.
|
|
nondet_throw(_) :- throw("nondet_throw").
|
|
|
|
:- pred multi_throw(string::out) is multi.
|
|
multi_throw(_) :- throw("multi_throw").
|
|
|
|
:- pred cc_nondet_throw(string::out) is cc_nondet.
|
|
cc_nondet_throw(_) :- throw("cc_nondet_throw").
|
|
|
|
:- pred cc_multi_throw(string::out) is cc_multi.
|
|
cc_multi_throw(_) :- throw("cc_multi_throw").
|
|
|
|
|
|
:- pred det_succeed(string::out) is det.
|
|
det_succeed("det_succeed").
|
|
|
|
:- pred semidet_succeed(string::out) is semidet.
|
|
semidet_succeed("semidet_succeed").
|
|
|
|
:- pred nondet_succeed(string::out) is nondet.
|
|
nondet_succeed("nondet_succeed 1").
|
|
nondet_succeed("nondet_succeed 2").
|
|
|
|
:- pred multi_succeed(string::out) is multi.
|
|
multi_succeed("multi_succeed 1").
|
|
multi_succeed("multi_succeed 2").
|
|
|
|
:- pred cc_nondet_succeed(string::out) is cc_nondet.
|
|
cc_nondet_succeed("cc_nondet_succeed").
|
|
cc_nondet_succeed("cc_nondet_succeed 2").
|
|
|
|
:- pred cc_multi_succeed(string::out) is cc_multi.
|
|
cc_multi_succeed("cc_multi_succeed").
|
|
cc_multi_succeed("cc_multi_succeed 2").
|
|
|
|
|
|
:- pred semidet_fail(string::out) is semidet.
|
|
semidet_fail("semidet_fail") :- fail.
|
|
|
|
:- pred nondet_fail(string::out) is nondet.
|
|
nondet_fail("nondet_fail 1") :- fail.
|
|
nondet_fail("nondet_fail 2") :- fail.
|
|
|
|
:- pred cc_nondet_fail(string::out) is cc_nondet.
|
|
cc_nondet_fail("cc_nondet_fail 1") :- fail.
|
|
cc_nondet_fail("cc_nondet_fail 2") :- fail.
|
|
|
|
|
|
:- pred nondet_succeed_then_throw(string::out) is nondet.
|
|
nondet_succeed_then_throw("nondet_succeed_then_throw 1").
|
|
nondet_succeed_then_throw("nondet_succeed_then_throw 2").
|
|
nondet_succeed_then_throw(_) :- throw("nondet_succeed_then_throw 3").
|
|
nondet_succeed_then_throw("nondet_succeed_then_throw 4").
|
|
|
|
:- pred multi_succeed_then_throw(string::out) is multi.
|
|
multi_succeed_then_throw("multi_succeed_then_throw 1").
|
|
multi_succeed_then_throw("multi_succeed_then_throw 2").
|
|
multi_succeed_then_throw(_) :- throw("multi_succeed_then_throw 3").
|
|
multi_succeed_then_throw("multi_succeed_then_throw 4").
|
|
|