:- set_prolog_flag(flowlog_engine, wam).

ok :-
    % Basic throw/catch.
    catch(throw(foo(a)), foo(X), X == a),

    % throw/1 argument must be nonvar -> instantiation_error.
    catch(throw(_), E1, E1 = error(instantiation_error, nonvar)),

    % Catcher can bind to a thrown term containing fresh variables.
    catch(throw(foo(_X)), E2, (E2 = foo(V), var(V))),

    % Inner catch does not catch mismatched exception; it must propagate.
    catch(catch(throw(bar), foo(_), true), bar, true),

    % Recover goal exceptions are not caught by the original catch/3.
    catch(catch(throw(foo), foo, throw(baz)), baz, true).

