[m-dev.] Pure Functional throwing exception
Julien Fischer
jfischer at opturion.com
Tue May 7 15:29:31 AEST 2019
Hi,
On Tue, 7 May 2019, Barthwal wrote:
> Can a pure function throw exceptions?
In Mercury, yes.
> I don't plan to catch these functions in pure function.
If you wanted to, you could. (Although doing so may affect
the determinism for your function.)
> But if something illegal happens, I want to send a message like:
>
> throw error("Some Message")
Assuming you don't catch the exception within your program, the
runtime's uncaught exception handler will print the exception out when
the exception propagates back past main/2. (It may also print a stack
trace if you're using a grade that records that information.)
As a general rule, I would recommend not throwing strings about. The
library has a builtin type named software_error/1 which is suitable for
exceptions where something illegal happens.
Julien.
More information about the developers
mailing list