[mercury-users] Exception handling in Mercury.

Bartlomiej Szymczak rhywek at gmail.com
Thu Jun 28 21:13:39 AEST 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.

I was trying to find a way of handling this exception, but I couldn't
find anything like "handle" in SML or "try"+"catch" in C++/Java.

Is there any way of handling this exception?

But even more useful thing for me would be raising exceptions from my
own code. Is there such a possibility?

I want to built a large lexicon module, so it's easy to misspell some
words or forget some. So if I look up a word in it and it's not there,
I want my program to terminate and tell me which word wasn't found
there. I could achieve it without exception throwing by passing the
!IO parameter all the way down to the lexicon lookup predicate, but
that's very artificial and almost impossible, as as the modules, which
use the lexicon, don't really need to do any input/output and they are
nondet. So throwing an exception would be just the perfect solution.

Thanks in advance for any help.

Best regards,
Bartlomiej Szymczak
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