[Actionframework-users] patch to AFWException.java
Status: Inactive
Brought to you by:
ptoman
From: Mark D. A. <md...@di...> - 2002-09-23 06:11:01
|
A useful addition to AFWException.java is: /** * Like printStackTrace(), but return into a string instead of writing to a stream. */ public String getStackTrace() { java.io.StringWriter w = new java.io.StringWriter(); this.printStackTrace(new java.io.PrintWriter(w, true)); return w.toString(); } This is useful because then error.vm can be: <html> <head> </head> <body bgcolor="white"> <h1><font color="red">Ack!</font></h1> #if ($error.StackTrace) <pre> $error.StackTrace </pre> #else <TT>$error</TT> #end </body> </html> this way, stack traces can be seen if the error variable is an exception object that has a getStackTrace method. Of course, that means overriding onException (unless Petr changes ActionServlet) so that "error" is an exception object in the context, and not a string: protected Template onException(Context context, String form, String action, org.actionframework.ActionException e) { // return error(context, org.actionframework.util.Util.filterSpecialHTMLChars(e.toString())); context.put("error", e); return getTemplate("error.vm"); } There still seem to be a whole bunch of different exceptions that are not caught by onException, which is a different problem.... -mda |