Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Jsp Printing a Stack Trace to the Server Console

Related Tutorials


 
 

Share on Google+Share on Google+

Printing a Stack Trace to the Server Console

Advertisement
When you generate an exception in a program, it will be better to print out the exception stack trace to catch the error instead of debugging jsp pages.

Printing a Stack Trace to the Server Console

     

In this section, you will study how the Stack Trace is printed on the Console.

When you generate an exception in a program, it will be better to print out the exception stack trace to catch the error instead of debugging jsp pages. By  the stack trace, you will know which method threw an exception and how that method is called. Instead of using getMessage() method of the exception to print errors during debugging process, you can use printStackTrace() method which prints a stack trace from the exception and provides more information about the error process.

Here is an example which illustrates you more clearly.

Here is the code (stackTrace.jsp):

<HTML>
<HEAD>
<TITLE>Printing a Stack Trace to the ServerConsole</TITLE>
</HEAD>
<BODY>
<H1>Print a Stack Trace to the Server Console</H1>
<%
try{
 int value = 5;
 value = value / 0;
 }
catch (Exception e){
e.printStackTrace();
}
%>
</BODY>
</HTML>

In the above example, we have generated an error by dividing the value by 0. Instead of using e.getMessage(), we have use e.printStackTrace() so that we can get more information about the error process.

Output will be displayed as

Download Source Code

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: August 5, 2008

Related Tutorials

Discuss: Printing a Stack Trace to the Server Console  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com