inaka/erlang_guidelines — pull request #24 by elbrujohalcon (2014-10-27 12:59:50+00:00)
Title: Rule: no nested try…catch blocks

##### rule
> Do not nest `try…catch` blocks

```erlang
bad() ->
try
maybe:throw(exception1),
try
maybe:throw(exception2),
"We are safe!"
catch
_:exception2 ->
"Oh, no! Exception #2"
end
catch
_:exception1 ->
"Bummer! Exception #1"
end.

good1() ->
try
maybe:throw(exception1),
maybe:throw(exception2),
"We are safe!"
catch
_:exception1 ->
"Bummer! Exception #1";
_:exception2 ->
"Oh, no! Exception #2"
end.

good2() ->
try
maybe:throw(exception1),
a_function:that_deals(with, exception2),
"We are safe!"
catch
_:exception1 ->
"Bummer! Exception #1"
end.
```

##### reasoning
Nesting `try…catch` blocks defeats the whole purpose of them, which is to isolate the code that deals with error scenarios from the nice and shinny code that deals with the expected execution path.