Analyzing Java Exceptions

A lot of Java programs use the getMessage() method of the IOException class to debug Java exceptions during development. This is usually accomplished as follows:

try {
    //"try" some piece of Java code here
}
catch (IOException e){

    System.out.println("Exception encountered: " + e.getMessage());
}

The previous technique doesn't give a lot of information about debugging the error. A better technique is to use the method printStackTrace() of the IOException class. This technique can be used to generate a stack trace from the exception. The stack trace provides more valuable information than a simple error text returned by getMessage().

Get e-Commerce Applications Using Oracle8i and Java from Scratch now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.