[mercury-users] Exception handling in Mercury.

Ralph Becket rafe at csse.unimelb.edu.au
Fri Jun 29 09:30:58 AEST 2007

Bartlomiej Szymczak, Thursday, 28 June 2007:
> Hi, all.
> My mercury code uses the hash_table module. I've read the library
> reference for it, and it says:
>         % Lookup the value associated with the given key. An
> exception is raised
>         % if there is no entry for the key.
>         %
>     :- func lookup(hash_table(K, V), K) = V.
>     :- mode lookup(hash_table_ui, in) = out is det.
> Guess what - indeed the exception was raised when I was testing my
> program. The program simply terminated. I've got excited, as I didn't
> know there were exceptions in Mercury.

You should have seen something printed out telling you what the uncaught
exception was.

However, from what you say catching misses via exceptions sounds like
the wrong approach: exceptions should be used for exceptional
circumstances, not expected circumstances.  You should consider instead
using hash_table.search(HashTable, Key, Value), which will simply fail
if there is no mapping for Key in HashTable.

-- Ralph
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