Referencing Exception subclasses in error.jsp?

Is it possible to reference Exception subclasses in the error.jsp page?If I throw a new exception called testException from a bean, how do I get access to it in my error.jsp page? It seems like I can only get access to Exception, not testException.
[283 byte] By [pafoege] at [2007-9-26 2:09:17]
# 1

Hi,

you need those RTTI stuff. Try this: create a class

public class MyException extends Exception

{

final private String mString = "Boo!";

public String getString()

{

return mString;

}

}

and let some JavaBean throw an object of this class. Now in your error.jsp you can do something like this

String messageToDisplay;

Class myExceptionClass = MyException.class;

Class exceptionClass = exception.getClass();

if (myExceptionClass.isAssignableFrom(exceptionClass))

{

MyException myException = (MyException) exception;

messageToDisplay = myException.getString();

}

else

{

messageToDisplay = exception.getMessage();

}

and write a JSP expression to display the message. I've tried this here with j2sdkee1.2.1, jdk1.3.1 and Tomcat 3.2.3 and it works as expected. Note: This is not bullet proof and there're maybe better solutions. Check the documentation and ask your friends about RTTI.

Further reading: JavaWorld, Java Tip 113: Identify subclasses at runtime, Daniel Le Berre, http://www.javaworld.com/javaworld/javatips/jw-javatip113.html

HTH,

Markus 'howlingmad' Neifer

Howlingmad at 2007-6-29 8:58:49 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...