Example usage for java.lang Throwable getCause

List of usage examples for java.lang Throwable getCause

Introduction

In this page you can find the example usage for java.lang Throwable getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:eu.stratosphere.pact.runtime.sort.AsynchonousPartialSorterITCase.java

private static boolean containsTriggerException(Throwable exception) {
    while (exception != null) {
        if (exception.getClass().equals(TriggeredException.class)) {
            return true;
        }/*from  w  w w .ja  v a  2s .co  m*/
        exception = exception.getCause();
    }
    return false;
}

From source file:com.runwaysdk.controller.ErrorUtility.java

public static void prepareAjaxThrowable(Throwable t, HttpServletResponse resp) throws IOException {
    while (t instanceof InvocationTargetException) {
        t = t.getCause();
    }// w  w  w  .j  a  v a 2  s  .  co  m

    if (t instanceof ProblemExceptionDTO) {
        JSONProblemExceptionDTO jsonE = new JSONProblemExceptionDTO((ProblemExceptionDTO) t);
        resp.setStatus(500);
        resp.getWriter().print(jsonE.getJSON());
    } else {
        JSONRunwayExceptionDTO jsonE = new JSONRunwayExceptionDTO(t);
        resp.setStatus(500);
        resp.getWriter().print(jsonE.getJSON());
    }
}

From source file:com.oracle.tutorial.jdbc.JDBCTutorialUtilities.java

public static void printSQLException(SQLException ex) {
    for (Throwable e : ex) {
        if (e instanceof SQLException) {
            if (ignoreSQLException(((SQLException) e).getSQLState()) == false) {
                e.printStackTrace(System.err);
                System.err.println("SQLState: " + ((SQLException) e).getSQLState());
                System.err.println("Error Code: " + ((SQLException) e).getErrorCode());
                System.err.println("Message: " + e.getMessage());
                Throwable t = ex.getCause();
                while (t != null) {
                    System.out.println("Cause: " + t);
                    t = t.getCause();
                }/*ww w  . j  a  va  2s .  c  om*/
            }
        }
    }
}

From source file:com.ethercamp.harmony.desktop.DesktopUtil.java

/**
 * Find initial exception by visiting/*  w ww  .java  2s.com*/
 */
public static Throwable findCauseFromSpringException(Throwable e) {
    final List<Class<? extends Exception>> skipList = Arrays.asList(BeansException.class,
            EmbeddedServletContainerException.class, ApplicationContextException.class);

    for (int i = 0; i < 50; i++) {
        final Throwable inner = e;
        final boolean isSkipped = skipList.stream().anyMatch(c -> c.isAssignableFrom(inner.getClass()));
        if (isSkipped) {
            e = e.getCause();
        } else {
            return e;
        }
    }
    return e;
}

From source file:embedding.events.ExampleEvents.java

/**
 * This method extracts the original exception from some exception. The exception
 * might be nested multiple levels deep.
 * @param t the Throwable to inspect/*from w  w  w .ja v a2s.  c  o  m*/
 * @return the original Throwable or the method parameter t if there are no nested Throwables.
 */
private static Throwable getOriginalThrowable(Throwable t) {
    if (t instanceof SAXException) {
        SAXException saxe = (SAXException) t;
        if (saxe.getException() != null) {
            return getOriginalThrowable(saxe.getException());
        } else {
            return saxe;
        }
    } else {
        if (t.getCause() != null) {
            return getOriginalThrowable(t.getCause());
        } else {
            return t;
        }
    }
}

From source file:com.aw.support.reflection.MethodInvoker.java

/**
 * Invoke specific method on the target and returns the value that this method returns
 *
 * @param target/*from   w w w  .java 2s. com*/
 * @param methodName
 * @return
 */
public static Object invoke(Object target, String methodName) throws Throwable {
    Object objectToReturn = null;
    try {
        Class cls = target.getClass();
        Method method = cls.getMethod(methodName, null);
        objectToReturn = method.invoke(target, null);
    } catch (Throwable e) {
        logger.error("Cannot execute class:" + target.getClass() + "method :" + methodName);
        Throwable cause = e.getCause();
        if ((cause instanceof FlowBreakSilentlyException) || (cause instanceof AWException)) {
            throw cause;
        }
        e.printStackTrace();
        throw e;
    }
    return objectToReturn;
}

From source file:com.revolsys.gis.tools.ProcessorPipelineTool.java

private static Throwable getBeanExceptionCause(final BeanCreationException e) {
    Throwable cause = e.getCause();
    while (cause instanceof BeanCreationException || cause instanceof MethodInvocationException
            || cause instanceof PropertyAccessException) {
        final Throwable newCause = cause.getCause();
        if (newCause != null) {
            cause = newCause;//  w  w  w.  j a v a 2  s.  c  om
        }
    }
    return cause;
}

From source file:com.nextep.designer.vcs.ui.impl.ExceptionHandler.java

/**
 * Handles exception within the neXtep designer environment. This method returns a boolean
 * indicating whether the exception handling should go on with Eclipse exception handling or if
 * it has been absorbed by neXtep.//from www .j  a  va 2  s  . com
 * 
 * @param t the exception to handle
 * @return <code>true</code> when the exception has been completely handled and should not be
 *         raised, else <code>false</code>.
 */
public static boolean handle(Throwable t) {
    if (t instanceof OutOfDateObjectException) {
        VersionUIHelper.promptObjectSynched(((OutOfDateObjectException) t).getStaleObject());
    } else if (t instanceof CancelException) {
        log.info(t.getMessage());
    } else if (t instanceof ErrorException) {
        if (t.getCause() instanceof InvocationTargetException) {
            t = t.getCause().getCause();
            return handle(t);
        }
        log.error(t.getMessage(), t);
        MessageDialog.openWarning(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                "Error when performing user action", t.getMessage());
        // if("true".equals(Designer.getInstance().getProperty("nextep.designer.debug"))) {
        // log.error(t);
        // }
    } else if (t instanceof ExitDesignerException) {
        log.info(t.getMessage());
    } else if (t instanceof JDBCConnectionException) {
        if (!Designer.getTerminationSignal()) {
            Designer.setTerminationSignal(true);
            try {
                // Ensuring a UI Thread
                Display.getDefault().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        // We are in a situation where we've lost our connection to the
                        // repository
                        MessageDialog.openError(null,
                                UIMessages.getString("exceptionHandler.repositoryConnectionLost.title"), //$NON-NLS-1$
                                UIMessages.getString("exceptionHandler.repositoryConnectionLost.message")); //$NON-NLS-1$
                        // Closing perpective
                        IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
                                .getActivePage();
                        page.closeAllPerspectives(true, true);
                        // Closing and reopening session
                        HibernateUtil.getInstance().reconnectAll();
                        // Changing view
                        final IWorkspaceUIService viewUiService = VCSUIPlugin
                                .getService(IWorkspaceUIService.class);
                        final IWorkspaceService viewService = VCSPlugin.getService(IWorkspaceService.class);
                        viewUiService.changeWorkspace(viewService.getCurrentWorkspace().getUID());
                    }
                });
            } finally {
                Designer.setTerminationSignal(false);
            }
        } else {
            log.error("Error thrown while reinitializing repository connection: " + t.getMessage(), t);
        }
        return true;
    } else {
        log.error("An error has been raised: " + t.getMessage(), t); //$NON-NLS-1$
        if (t instanceof HibernateException && PlatformUI.getWorkbench() != null
                && PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null) {
            MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                    UIMessages.getString("systemInstableTitle"), UIMessages //$NON-NLS-1$
                            .getString("systemInstable")); //$NON-NLS-1$
        }
    }
    if (Designer.isDebugging()) {
        t.printStackTrace();
    }
    // By default we consider that we haven't handled completely the problem
    return false;
}

From source file:net.sf.taverna.t2.activities.beanshell.BeanshellActivity.java

private static String determineMessage(Throwable e) {
    if (e instanceof TargetError) {
        Throwable t = ((TargetError) e).getTarget();
        if (t != null) {
            return t.getClass().getCanonicalName() + ": " + determineMessage(t);
        }//from  w  ww.j a  v a  2s  .  c om
    }
    Throwable cause = e.getCause();
    if (cause != null) {
        return determineMessage(cause);
    }
    return e.getMessage();
}

From source file:eu.eidas.node.utils.EidasNodeErrorUtil.java

/**
 *
 * @param e//from   w  ww.j  a  v a2  s.c  o  m
 * @return the base SAML engine exception
 */
public static Exception getBaseSamlException(EIDASSAMLEngineException e) {
    Exception baseExc = e;
    Throwable currentException = e;
    while (true) {
        if (currentException != null && currentException.getCause() != null
                && currentException != currentException.getCause()) {
            currentException = currentException.getCause();
            if (isSAMLEngineException(currentException)) {
                baseExc = (Exception) currentException;
            }
        } else {
            break;
        }
    }
    return baseExc;
}