Java XML Transform Usage unwrapException(Throwable t)

Here you can find the source of unwrapException(Throwable t)

Description

unwrap Exception

License

Open Source License

Return

Throwable input or tail of any wrapped exception chain

Declaration

public static Throwable unwrapException(Throwable t) 

Method Source Code

//package com.java2s;
/* *******************************************************************
 * Copyright (c) 1999-2001 Xerox Corporation, 
 *               2002 Palo Alto Research Center, Incorporated (PARC).
 * All rights reserved. /* w  ww .  j  ava 2s  . c om*/
 * This program and the accompanying materials are made available 
 * under the terms of the Eclipse Public License v1.0 
 * which accompanies this distribution and is available at 
 * http://www.eclipse.org/legal/epl-v10.html 
 *  
 * Contributors: 
 *     Xerox/PARC     initial implementation 
 * ******************************************************************/

import java.lang.reflect.InvocationTargetException;
import java.security.PrivilegedActionException;
import java.sql.SQLException;

public class Main {
    /** @return Throwable input or tail of any wrapped exception chain */
    public static Throwable unwrapException(Throwable t) {
        Throwable current = t;
        Throwable next = null;
        while (current != null) {
            // Java 1.2 exceptions that carry exceptions
            if (current instanceof InvocationTargetException) {
                next = ((InvocationTargetException) current).getTargetException();
            } else if (current instanceof ClassNotFoundException) {
                next = ((ClassNotFoundException) current).getException();
            } else if (current instanceof ExceptionInInitializerError) {
                next = ((ExceptionInInitializerError) current).getException();
            } else if (current instanceof PrivilegedActionException) {
                next = ((PrivilegedActionException) current).getException();
            } else if (current instanceof SQLException) {
                next = ((SQLException) current).getNextException();
            }
            // ...getException():
            // javax.naming.event.NamingExceptionEvent
            // javax.naming.ldap.UnsolicitedNotification
            // javax.xml.parsers.FactoryConfigurationError
            // javax.xml.transform.TransformerFactoryConfigurationError
            // javax.xml.transform.TransformerException
            // org.xml.sax.SAXException
            // 1.4: Throwable.getCause
            // java.util.logging.LogRecord.getThrown()
            if (null == next) {
                break;
            } else {
                current = next;
                next = null;
            }
        }
        return current;
    }
}

Related

  1. renderElement(Element theElem)
  2. safeToXml(Element element)
  3. streamSource(File file)
  4. toNonValidatingSAXSource(InputStream in)
  5. toXMLInputSource(StreamSource in)
  6. verifySignature(Element element, PublicKey validatingKey)
  7. writeElementContent(XMLInputFactory inputFactory, XMLStreamWriter writer, Element element)
  8. writeXhtml(InputStream inputStream, Writer writer, Templates... templates)
  9. xsl(File inFile, File outFile, InputStream xslStream)