commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cost...@covalent.net
Subject Re: DBCP/LANG
Date Tue, 13 Aug 2002 20:00:11 GMT
Aha ! I knew they are used somewhere. 

I personally prefer using introspection - getNextException, getCause, etc
are common patterns, so just casting to SAX and SQL exceptions only
handles the 'origin' of this naming patern.

And let's not forget 'detail' - JAXRPC is using RemoteException ( and
axis is one implementing that ). 

Costin

On Tue, 13 Aug 2002, Nicola Ken Barozzi wrote:

> 
> Jack, Paul wrote:
> >>Well, seriously speaking there are few other patterns I've seen:
> >>  getNextException
> >>  getRootCause
> >>  getException
> > 
> > 
> > Plus getTargetException() used by
> > java.lang.reflect.InvocationTargetException,
> > quite common.
> 
> Here is the relevent code from a Cocoon class
> (http://cvs.apache.org/viewcvs.cgi/xml-cocoon2/src/java/org/apache/cocoon/components/notification/DefaultNotifyingBuilder.java?rev=HEAD&content-type=text/vnd.viewcvs-markup)
> that does some exception walk, also with SAXExceptions.
> 
>    /**
>     * Print recursively all nested causes of a Throwable in a PrintWriter.
>     */
>    private static void appendCauses (PrintWriter out, Throwable t) {
>      Throwable cause = null;
>      if (t instanceof CascadingThrowable) {
>        cause = ((CascadingThrowable) t).getCause();
>      } else if (t instanceof SAXException) {
>        cause = ((SAXException) t).getException();
>      } else if (t instanceof java.sql.SQLException) {
>        cause = ((java.sql.SQLException) t).getNextException();
>      }
>      if (cause != null) {
>        out.print("Original exception : ");
>        cause.printStackTrace(out);
>        out.println();
>        // Recurse
>        appendCauses(out, cause);
>      }
>    }
> 
>    /**
>     * Get root Exception.
>     */
>    private static Throwable getRootCause (Throwable t) {
>      Throwable cause = null;
>      if (t instanceof CascadingThrowable) {
>        cause = ((CascadingThrowable) t).getCause();
>      } else if (t instanceof SAXException) {
>        cause = ((SAXException) t).getException();
>      } else if (t instanceof java.sql.SQLException) {
>        cause = ((java.sql.SQLException) t).getNextException();
>      }
>      if (cause == null) {
>        return t;
>      } else {
>        // Recurse
>        return getRootCause(cause);
>      }
>    }
> 
> 
> 


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message