The Exception Object in JSP

By: Sathya Narayana  

The exception object is an instance of the java.lang.Throwable class. It's available in error pages only, and it represents the exception that occurred that caused control to pass to the error page. Its most useful methods are as follows.

getLocalizedMessage() returns a localized description of this Throwable object. In many cases, this will return the same result as getMessage():

public String getLocalizedMessage()

getMessage() returns the error message string of this Throwable object:

public String getMessage()

printStackTrace() prints information about this Throwable object, along with a listing of the method calls that led to the error condition arising. The output can be directed to the standard error stream or to a specified PrintStream or PrintWriter object:

public void printStackTrace()
public void printStackTrace(PrintStream ps)
public void printStackTrace(PrintWriter pw)

toString() returns a short description of this Throwable object:

public String toString()

If an error message was supplied when the object was created, the result is the Throwable class's name, followed by a colon and a space, followed by that message. For example, the following:

<%
try
{
throw new Exception("Here's my Exception");
}
catch(Exception e)
{
out.print(e.toString());
}
%>

outputs the following: java.lang.Exception: Here's my Exception.




Archived Comments


Most Viewed Articles (in JSP )

Latest Articles (in JSP)

Comment on this tutorial