[erlang-questions] When to catch (was: Module config data and functional programming)

Loïc Hoguin essen@REDACTED
Mon Sep 5 19:41:52 CEST 2011


On 09/04/2011 03:31 AM, Daniel Dormont wrote:
> This was an earlier thread of mine that inspired a new question.
> 
> As the months go by I'm getting more comfortable with "let it crash"
> as an idea and seeing its benefits. But it occurs to me: surely there
> are exceptions. Or rather: in order for "let it crash" to work at one
> level of abstraction or functionality, there must be actual
> crash-handling code at a level beneath it. In Erlang, this seems to
> often involve letting individual processes crash and their supervisors
> react accordingly. But perhaps that's not always the right answer. So
> my question is:
> 
> When is "catch" the right tool for the job? In the example below,
> Ejabberd's "hooks" handlers use catch when calling functions in
> foreign modules that are (probably) not critical path to whatever it's
> doing. That seems like a pretty decent case to me. Would you agree?
> What are some cases common in Erlang where exceptions need to be
> caught and handled (or ignored) within a single process?

Another use:

You should catch when you run foreign code from the same process.
Examples of this include gen_server, gen_fsm and friends. The gen_server
code will call functions defined in your module, which can crash.
gen_server will catch exceptions to print a meaningful error and cleanup.

-- 
Loïc Hoguin
Dev:Extend



More information about the erlang-questions mailing list