Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Java
Expertise: All
May 26, 1999



Application Security Testing: An Integral Part of DevOps

Avoid Empty Exception Handlers

One of the most frustrating experiences when running a Java program is an empty line where you expect information about a thrown exception. The programmer probably meant to catch the exception but did nothing with it. As a result, when the exception is thrown at run time, there is no way to indicate to the user that it was thrown, which leads to erroneous results. For example, consider a method called method1 that throws an exception.
1. private void method1 () throws Exception {
2.   // Do stuff
3.   throw new Exception();
4. }
Now consider this code:
1.     System.out.println("Start");
3.     try {
4.       method1();
5.     }
6.     catch (Exception e) {
8.     }
9.     System.out.println("End OK");
You catch the exception on Line 6. However, the program does nothing with the exception. The result is that at run time, there is no trace of the exception; it becomes nonexistent. The output of the code excerpt is:
End OK
Therefore, you should avoid empty exception handlers as good programming practice.
Ajit Sagar
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date