Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a situation when it's appropriate to use empty catch block? [duplicate]

Possible Duplicates:
Why are empty catch blocks a bad idea?
Is there any valid reason to ever ignore a caught exception

Do you know any situations when an empty catch block is not the absolute evil?

try
{
    ...
    // What and When?
    ...
}
catch { }
like image 258
bniwredyc Avatar asked Jan 14 '11 14:01

bniwredyc


2 Answers

There are a lot of questions on this, try to look at:

Why are empty catch blocks a bad idea?

From that post's accepted answer:

Usually empty try-catch is a bad idea because you are silently swallowing an error condition and then continuing execution. Occasionally this may be the right thing to do, but often it's a sign that a developer saw an exception, didn't know what to do about it, and so used an empty catch to silence the problem.

It's the programming equivalent of putting black tape over an engine warning light.

like image 85
as-cii Avatar answered Oct 10 '22 00:10

as-cii


Take a look at this, it basically breaks down the kind of exceptions you could encounter into four categories, none of which should be handled by an empty catch block.

like image 41
SWeko Avatar answered Oct 10 '22 00:10

SWeko