[ 
http://issues.apache.org/jira/browse/XERCESJ-1186?page=comments#action_12433685 
] 
            
elharo commented on XERCESJ-1186:
---------------------------------

This can be addressed in 1.2 and later. All you need to do is reimplement the 
initCause, getCause mechanism from Java 1.4 in the exception classes. JDOM does 
this, XOM does this. Probably others as well. The basic code looks like this:

    private Throwable cause;
    public Throwable getCause() {
        return this.cause;  
    }

    
    // null is insufficient for detecting an uninitialized cause.
    // The cause may be set to null which may not then be reset.
    private boolean causeSet = false;

    
    /**
     * <p>
     * Sets the root cause of this exception. This may 
     * only be called once. Subsequent calls throw an 
     * <code>IllegalStateException</code>.
     * </p>
     * 
     * <p>
     * This method is unnecessary in Java 1.4 where it could easily be
     * inherited from the superclass. However, including it here
     * allows this  method to be used in Java 1.3 and earlier.
     * </p>
     *
     * @param cause the root cause of this exception
     * 
     * @return this <code>XMLException</code>
     * 
     * @throws IllegalArgumentException if the cause is this exception
     *   (An exception cannot be its own cause.)
     * @throws IllegalStateException if this method is called twice
     */
    public final Throwable initCause(Throwable cause) {
        
        if (causeSet) {
            throw new IllegalStateException("Can't overwrite cause");
        } 
        else if (cause == this) {
            throw new IllegalArgumentException("Self-causation not permitted"); 
        }
        else this.cause = cause;
        causeSet = true;
        return this;
        
    }

In Java 1.4 and later these redundantly override the base methods. In 1.2 and 
1.3 they provide those methods. Either way, it works. 

> [PATCH] retain exception stack traces
> -------------------------------------
>
>                 Key: XERCESJ-1186
>                 URL: http://issues.apache.org/jira/browse/XERCESJ-1186
>             Project: Xerces2-J
>          Issue Type: Improvement
>    Affects Versions: 2.8.0
>            Reporter: Dave Brosius
>            Priority: Minor
>         Attachments: retain_stack_traces.diff
>
>
> When a different exception is thrown from a catch block, you lose the 
> original stack trace where the exception occurred, making it more difficult 
> to figure out what went wrong. Add code to initialize the thrown exception's 
> initial cause, so the stack traces are retained.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to