Skip to main content
xenoveritas.org

Main navigation

  • Categories
  • Home
  • Links
  • Name Generator
  • Scramble
User account menu
  • Log in

Breadcrumb

  1. Home

"What exception? La-la-la-la-la, I can't hear you! LA-LA-LA-LA-LA!"

By Xenoveritas, 2 May, 2006
Topics
Technology
  • Add new comment

I'm really getting tired of the "I did this to shut up the compiler" anti-pattern, where something gets done simply to surpress a warning without any thought going into why the warning was generated.

The most annoying one has to be the "La-la-la, I can't hear you!" anti-pattern. It's simply:

try {
    doSomething();
} catch (Exception e) {
    //
}

Most frequently this gets done to avoid having to listen to the compiler complain about unchecked exceptions. But it totally screws up later code that really does need to know when attempting to connect to the database didn't succeed due to that annoying SQLException that you're ignoring.

Generally speaking, if you can't handle an exception (and there are plenty of cases where that's true), you should just declare it in the throws clause and not simply eat it. Eventually, someone, somewhere, will be able to handle it properly - most likely, displaying an error message to the user, or possibly recovering from the error.

There are times when you do want to ignore certain exceptions. However, in those cases, there should be comments explaining why the exception is ignored. Flat out ignoring warnings or errors is wrong!

In the cases where errors or warnings should be ignored, then it's necessary that comments explain exactly why the warning can be safely ignored.

Current Games

I'm currently playing:

  • Final Fantasy XIV: Endwalker

I intend to maybe get around to finishing:

  • Literally anything else

Video Games Section

Thought for the Moment

I never have thoughts any more.

Old Thoughts

Has the LHC Destroyed the Earth?

  • Create new account
  • Reset your password
RSS feed
Powered by Drupal