[mercury-users] question about error/1

Nicholas Nethercote njn at csse.unimelb.edu.au
Thu Jan 24 16:37:37 AEDT 2008


On Thu, 24 Jan 2008, Ralph Becket wrote:

> Talking to Nick, I think what he wants is something like
> abort_with_my_error_message_and_no_window_dressing(string).
>
> You can code this up fairly easily at the top-level:
>
> :- pred main(io::di, io::uo) is cc_multi.
>
> main(!IO) :-
> 	try_io(my_main, Result, !IO),
> 	(
> 		Result = succeeded(_)
> 	;
> 		Result = exception(Excn),
> 		( if Excn = univ.value(no_window_dressing(ErrMsg)) then
> 			io.write_string(io.stderr_stream, ErrMsg, !IO),
> 			io.nl(io.stderr_stream, !IO),
> 			io.set_exit_status(1, 1IO)
> 		  else
> 		  	rethrow(Result)
> 		)
> 	).
>
> :- pred my_main(dummy_value::out, io::di, io::uo) is det.
>
> my_main(dummy_value, !IO) :-
> 	... business as usual ...
>
> :- type no_window_dressing ---> no_window_dressing(string).
>
> :- pred abort_with_my_error_message_and_no_window_dressing(string::in)
> 	is erroneous.
>
> abort_with_my_error_message_and_no_window_dressing(ErrMsg) :-
> 	throw(no_window_dressing(ErrMsg)).

That's quite a mouthful, particularly since I'm generating the Mercury 
program rather than writing it by hand.

Either Mark's or Peter's suggestions would be fine by me -- I don't 
particularly care about the mechanism.

Nick
--------------------------------------------------------------------------
mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the users mailing list