[erlang-bugs] handling of uncaught exceptions in behavour callbacks

Richard Carlsson carlsson.richard@REDACTED
Wed Apr 25 20:20:08 CEST 2012


On 2012-04-25 17:33, Fred Hebert wrote:
> I would also agree to see this as a bug.
>
> Regarding the fix, wouldn't rewriting it to use a try ... of ... catch
> negate the problem entirely by being able to make the distinction
> between a throw and a returned value?
>
> try Mod:some_callback(...) of
> ...
> Other -> exit({bad_return_value, Other}
> catch
> _:Reason -> exit(Reason)
> end
>
> or something similar, as long as we keep similar error/exit semantics?

It's the "similar" that's the issue here. What can we change without 
breaking too much existing code? That's why I would like a clear 
statement from the OTP team before I try to create a patch.

> I figure the throw could be seen as the standard bubbling thing where
> throw becomes an error, which becomes an error before the process dies.

Yes, I think that an uncaught throw should turn into error({nocatch, 
Term}), but there's also the question of whether 'error' exceptions 
should be turned into exits as it is done now in gen_server. It would 
probably be nicest if the gen_server framework didn't affect the exit 
signal sent by a process when it dies: if spawn(M,F,[...]) sends out 
signal X in a particular situation, then if you wrap M:F(...) using the 
gen_server library, the process should still send out X in the same 
situation. That's not the case today however, and the question is, can 
we make it so without upsetting too much old code?

    /Richard



More information about the erlang-bugs mailing list