Over a million developers have joined DZone.

Coding Crimes: Ignoring Exceptions

DZone's Guide to

Coding Crimes: Ignoring Exceptions

· Java Zone
Free Resource

Microservices! They are everywhere, or at least, the term is. When should you use a microservice architecture? What factors should be considered when making that decision? Do the benefits outweigh the costs? Why is everyone so excited about them, anyway?  Brought to you in partnership with IBM.

Templates in IDEs such as Eclipse and NetBeans are a great feature. In particular, quick fix items such as "surround with try/catch" can save a lot of typing time. But, as with all things, the power given to the developer can be mis-used. This has got to be one of the worst coding crimes. 

Depending on your IDE and the templates you use, you'll probably get this: 


} catch (Exception e)
// TODO: handle exception

Or, maybe you'll at least get the exception written out to console.


} catch (IOException e)
// TODO Auto-generated catch block

For a start, the exception should be logged at the very least, not just written out to the console.  Also, in most cases, the exception should be thrown back to the caller for them to deal with. If it doesn't need to be thrown back to the caller, then the exception should be handled. And some comments would be nice too. 

The usual excuse for this type of code is "I didn't have time", but there is a ripple effect when code is left in this state. Chances are that most of this type of code will never get out in the final production. Code reviews or static analysis tools should catch this error pattern. But that's no excuse, all this does is add time to the maintainance and debugging of the software.  This also makes you question TODOs, and brings me back to my previous thoughts on writing the best code from the very start. 

Discover how the Watson team is further developing SDKs in Java, Node.js, Python, iOS, and Android to access these services and make programming easy. Brought to you in partnership with IBM.


Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}