2013/4/27 Daniel Macedo <admac...@gmail.com>

> Sorry but I disagree, I think you're approaching try-catch wrong.
>
> You shouldn't have a try-catch that *can* continue on the next line after
> the throw.
> What you should do is have decoupled code that handles _their own
> exceptions_ nicely and either cleans up after itself else it rethrows the
> exception/a new one.
>
> Any top level try-catch is supposed to be a control structure with one of
> two chances: either lines 1-N go smoothly and no exceptions are thrown, or
> Exception_X is thrown and you clean up on it's catch block...
>

It's an opinion, a software engineering choice. Not something that must be
enforced by the language.

It could be very useful in some situations, not all the time (as traits,
for example).
Ideally, every errors (in fact, any abnormal situation) should raise an
exception, right? OK, but that doesn't mean that any abnormal situation
should be able to break execution flow, with no other solution than writing
more code.


Also remember that you have the finally block.
>

Can you explain how the finally block can help in my example?

Reply via email to