5

I am not sure about this answer. I cant find it anywhere. Is it the empty error handling?!

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Emily Myers
  • 83
  • 1
  • 1
  • 4
  • 1
    See also [*Never 'swallow' exceptions in your code*](http://www.pscode.org/javafaq.html#stacktrace). – trashgod Sep 19 '12 at 02:14
  • 2
    It's called an incredibly bad idea ;) – MadProgrammer Sep 19 '12 at 02:39
  • 2
    @MadProgrammer IMO though a little too broad, 'an incredibly bad idea' is a valid answer to the question. – Andrew Thompson Sep 19 '12 at 03:00
  • 1
    @AndrewThompson I've been working a monolithic application for the past 3 years where the previous developer felt it was okay to "consume" most exceptions...without even logging them. I spent half a day yesterday stepping through code trying to find where the application had suddenly decided to stop to find...and empty try/catch...IMHO, it's an incredibly bad idea, cause know I want to kill him :P (and God only knows how many more we're yet to find) – MadProgrammer Sep 19 '12 at 03:08

7 Answers7

5

It is known as suppressing the exception, or swallowing the exception. May not be a very good practice, unless commented with a very good reason.

Adeel Ansari
  • 39,541
  • 12
  • 93
  • 133
4

We affectionately call this "eating the exception" at work. Basically, it means that something bad occurred, and we are burying our head in the sand and pretending it never happened. At the very least, a good practice is to have a logger.error(e) within that block:

try {
   // code here
}
catch (Exception e) { logger.error(e); }

so that you will have it recorded somewhere that an exception occurred.

Philip Tenn
  • 6,003
  • 8
  • 48
  • 85
  • From all the answers I read here I like this the best because you should never just comment why your swallowing the exception. You need to log an error at the very least! – ramsinb Sep 19 '12 at 02:52
2

As far as I know, it's simply called an "empty catch clause" (or perhaps silent exception consumption), and it should generally be avoided (either handle the exception properly or don't try to catch it at all).

arshajii
  • 127,459
  • 24
  • 238
  • 287
2

This is generally called as ignoring an exception. Other terms used are Consuming an exception silently, Eating an exception etc

Community
  • 1
  • 1
Nivas
  • 18,126
  • 4
  • 62
  • 76
1

It's called "broken code".

(if you want to ignore an exception, then clearly document the reason.)

jtahlborn
  • 52,909
  • 5
  • 76
  • 118
1

From what i know, this means that in fancy talk "Eating the exception", but simply it just stops this specific error from stoping java while its running your code. Also the "e" part in the

    catch (Exception *e*) {}

is the "name" for the error object.

if you're still unsure about whats that then read this.

KidOfCubes
  • 11
  • 1
  • 2
0

I call it "exception masking" and it is not good style. It is best to catch specific exceptions or let them "bubble up". Masking exceptions will come back to bite you. It is a good idea to have the exceptions bubble up to be appropriately handled. If the exception "bubbles to the top", a proactive exception handler can be developed to notify the developer or organization that an unexpected exception has occurred.

Bill Bunting
  • 521
  • 6
  • 28