[m-users.] [m-dev.] Pure Functional throwing exception
charles.shuller at gmail.com
Wed May 8 23:45:50 AEST 2019
In the below message you mentioned it would be better NOT to do:
exception.throw("Badness happened, terminating")
Which is something I do quite a lot of to get a non-local exit. As in,
the exception should never be handled, I just want the program to halt with
some appropriate error message.
It sounded like you recommended the following instead (note the addition of
exception.throw( exception.software_error("Badness happened,
Which is a bit more typing, but I don't see how this makes things any
better. A new type for each kind of exception makes sense to me if I
wanted to handle my exceptions, but boxing all messages as software_error
types doesn't intuitively make sense to me.
Can you explain your reasoning for me??
On Tue, May 7, 2019 at 12:29 AM Julien Fischer <jfischer at opturion.com>
> 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.
> developers mailing list
> developers at lists.mercurylang.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the users