Tuesday, May 19, 2009

JExceptionReporter

JExceptionReporter shows short or detail exception report in graphical user interface. Generally we show the Java exception stack trace in console by calling printStackTrace method. If you want to show the stack trace in graphical mode, you can use the JExceptionReporter.

Just call the showExceptionReport method of JExceptionReporter giving the Exception object in your catch block like below:

try
{
double number1=Double.parseDouble(txtFirstNumber.getText());
double number2=Double.parseDouble(txtSecondNumber.getText());
txtResult.setText(String.valueOf(number1/number2));
}
catch(NumberFormatException nfe)
{
JExceptionReporter.showExceptionReport(nfe);
}
catch(ArithmeticException ae)
{
JExceptionReporter.showExceptionReport(ae);
}

Then you will see the following output if any exception occurs in runtime.




Initially it will show the short message (what exception occurred) only but it will show the details stack trace if you click ‘Show Details’ button. Again you can shorten it by clicking the ‘Hide Details’ button.





Downloads:

Executable Jar File : JExceptionReporter.jar

NetBeans Project : JExceptionReporter.zip

Individual Java Source File : JExceptionReporter.java , TestJExceptionReporter.java

0 comments:

Template by - Abdul Munir | Daya Earth Blogger Template