Here you can find the source of unwrapException(Throwable t)
public static Throwable unwrapException(Throwable t)
//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; } }