Example usage for java.lang Throwable equals

List of usage examples for java.lang Throwable equals

Introduction

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

Prototype

public boolean equals(Object obj) 

Source Link

Document

Indicates whether some other object is "equal to" this one.

Usage

From source file:edu.osu.ling.pep.Pep.java

/**
 * Prints a throwable.//w w  w .  ja va 2s  .c  o m
 * 
 * @param error
 *            The throwable that was intercepted.
 * @see #printError(String)
 */
private static void printError(final Throwable error) {
    if (error instanceof SAXParseException) {
        final SAXParseException spe = (SAXParseException) error;
        Pep.printError("line " + spe.getLineNumber() + ": " + spe.getMessage());
    } else {
        String msg = error.getMessage();
        final Throwable cause = error.getCause();
        if (cause != null && !cause.equals(error)) {
            msg += ": " + cause.getMessage();
        }

        Pep.printError(msg);
    }
}

From source file:org.echocat.jomon.spring.ContextLoadThreadGroup.java

public <T extends Throwable> void throwOn(@Nonnull Class<T> allowedThrowableType) throws T {
    synchronized (_failedThreads) {
        final Throwable highestRatedThrowable = findHighestRatedThrowableIn(_failedThreads);
        if (highestRatedThrowable != null) {
            for (final List<Throwable> throwables : _failedThreads.values()) {
                for (final Throwable throwable : throwables) {
                    if (!highestRatedThrowable.equals(throwable)) {
                        highestRatedThrowable.addSuppressed(throwable);
                    }//from w  w  w . jav  a  2  s  .c om
                }
            }
            if (allowedThrowableType.isInstance(highestRatedThrowable)) {
                throw allowedThrowableType.cast(highestRatedThrowable);
            } else if (highestRatedThrowable instanceof RuntimeException) {
                throw (RuntimeException) highestRatedThrowable;
            } else if (highestRatedThrowable instanceof Error) {
                throw (Error) highestRatedThrowable;
            } else {
                throw new RuntimeException(highestRatedThrowable);
            }
        }
    }
}

From source file:adalid.commons.velocity.Writer.java

private void error(Throwable throwable) {
    Throwable cause = ThrowableUtils.getCause(throwable);
    String message = throwable.equals(cause) ? throwable.getClass().getSimpleName() : throwable.getMessage();
    logger.error(message, cause);/*from w w  w . j a va  2s.co  m*/
    errors++;
}

From source file:adalid.core.Project.java

private void fatal(Throwable throwable) {
    Throwable cause = ThrowableUtils.getCause(throwable);
    String message = throwable.equals(cause) ? throwable.getClass().getSimpleName() : throwable.getMessage();
    logger.fatal(message, cause);//w w  w.j a  v a2  s.com
}

From source file:org.codehaus.groovy.grails.web.errors.GrailsExceptionResolver.java

/**
 * Obtains the root cause of the given exception
 * @param ex The exception// www .  j a  va2s.  c o m
 * @return The root cause
 */
public static Throwable getRootCause(Throwable ex) {
    while (ex.getCause() != null && !ex.equals(ex.getCause())) {
        ex = ex.getCause();
    }
    return ex;
}

From source file:org.codehaus.groovy.grails.web.errors.GrailsExceptionResolver.java

public static RuntimeException getFirstRuntimeException(Throwable e) {
    if (e instanceof RuntimeException)
        return (RuntimeException) e;

    Throwable ex = e;
    while (ex.getCause() != null && !ex.equals(ex.getCause())) {
        ex = ex.getCause();//from   w w  w . jav a2  s.  c o  m
        if (ex instanceof RuntimeException)
            return (RuntimeException) ex;
    }
    return null;
}

From source file:org.jumpmind.db.sql.JdbcSqlTemplate.java

protected SQLException findSQLException(Throwable ex) {
    if (ex instanceof SQLException) {
        return (SQLException) ex;
    } else {/*from ww w  .j  a  va  2  s  . c  o  m*/
        Throwable cause = ex.getCause();
        if (cause != null && !cause.equals(ex)) {
            return findSQLException(cause);
        }
    }
    return null;
}

From source file:org.openmrs.module.uiframework.PageController.java

/**
 * @param path should be of the form "provider/optional/subdirectories/pageName"
 * @param request//  w ww .  j a  v  a 2s .c  o m
 * @param response
 * @param model
 * @param httpSession
 * @return
 */
public String handlePath(String path, HttpServletRequest request, HttpServletResponse response, Model model,
        HttpSession httpSession) {
    // handle the case where the url has two slashes, e.g. host/openmrs//emr/patient.page
    if (path.startsWith("/")) {
        path = path.substring(1);
    }
    int index = path.indexOf("/");
    if (index < 0) {
        throw new IllegalArgumentException(
                "page request must have at least provider/pageName, but this does not: "
                        + request.getRequestURI());
    }
    String providerName = path.substring(0, index);
    String pageName = path.substring(index + 1);

    Session session;
    try {
        session = sessionFactory.getSession(httpSession);
    } catch (ClassCastException ex) {
        // this means that the UI Framework module was reloaded
        sessionFactory.destroySession(httpSession);
        session = sessionFactory.getSession(httpSession);
    }
    PageRequest pageRequest = new PageRequest(providerName, pageName, request, response, session);
    try {
        String html = pageFactory.handle(pageRequest);
        model.addAttribute("html", html);
        return SHOW_HTML_VIEW;
    } catch (Redirect redirect) {
        String ret = "";
        if (!redirect.getUrl().startsWith("/"))
            ret += "/";
        ret += redirect.getUrl();
        if (ret.startsWith("/" + WebConstants.CONTEXT_PATH)) {
            ret = ret.substring(WebConstants.CONTEXT_PATH.length() + 1);
        }
        return "redirect:" + ret;
    } catch (FileDownload download) {
        response.setContentType(download.getContentType());
        response.setHeader("Content-Disposition", "attachment; filename=" + download.getFilename());
        try {
            IOUtils.copy(new ByteArrayInputStream(download.getFileContent()), response.getOutputStream());
            response.flushBuffer();
        } catch (IOException ex) {
            throw new UiFrameworkException("Error trying to write file content to response", ex);
        }
        return null;
    } catch (PageAction action) {
        throw new RuntimeException("Not Yet Implemented: " + action.getClass(), action);
    } catch (RuntimeException ex) {
        // special-case if this is due to the user not being logged in
        APIAuthenticationException authEx = ExceptionUtil.findExceptionInChain(ex,
                APIAuthenticationException.class);
        if (authEx != null) {
            throw authEx;
        }

        // The following should go in an @ExceptionHandler. I tried this, and it isn't getting invoked for some reason.
        // And it's not worth debugging that.

        StringWriter sw = new StringWriter();
        ex.printStackTrace(new PrintWriter(sw));
        model.addAttribute("fullStacktrace", sw.toString());

        Throwable t = ex;
        while (t.getCause() != null && !t.equals(t.getCause()))
            t = t.getCause();
        sw = new StringWriter();
        t.printStackTrace(new PrintWriter(sw));
        model.addAttribute("rootStacktrace", sw.toString());

        return "/module/uiframework/uiError";
    }
}

From source file:org.openmrs.module.xforms.page.controller.PatientRegUrlHandler.java

/**
  * @param path should be of the form "provider/optional/subdirectories/pageName"
  * @param request/* w  w w .j  a v  a 2  s . c  om*/
  * @param response
  * @param model
  * @param httpSession
  * @return
  */
public String handlePath(String path, HttpServletRequest request, HttpServletResponse response, Model model,
        HttpSession httpSession) {
    // handle the case where the url has two slashes, e.g. host/openmrs//emr/patient.page
    if (path.startsWith("/")) {
        path = path.substring(1);
    }
    int index = path.indexOf("/");
    if (index < 0) {
        throw new IllegalArgumentException(
                "page request must have at least provider/pageName, but this does not: "
                        + request.getRequestURI());
    }
    String providerName = path.substring(0, index);
    String pageName = path.substring(index + 1);

    Session session;
    try {
        session = sessionFactory.getSession(httpSession);
    } catch (ClassCastException ex) {
        // this means that the UI Framework module was reloaded
        sessionFactory.destroySession(httpSession);
        session = sessionFactory.getSession(httpSession);
    }
    PageRequest pageRequest = new PageRequest(providerName, pageName, request, response, session);
    try {
        String html = pageFactory.handle(pageRequest);
        model.addAttribute("html", html);
        return SHOW_HTML_VIEW;
    } catch (Redirect redirect) {
        String ret = "";
        if (!redirect.getUrl().startsWith("/"))
            ret += "/";
        ret += redirect.getUrl();
        if (ret.startsWith("/" + WebConstants.CONTEXT_PATH + "/")) {
            ret = ret.substring(WebConstants.CONTEXT_PATH.length() + 1);
        }
        return "redirect:" + ret;
    } catch (FileDownload download) {
        response.setContentType(download.getContentType());
        response.setHeader("Content-Disposition", "attachment; filename=" + download.getFilename());
        try {
            IOUtils.copy(new ByteArrayInputStream(download.getFileContent()), response.getOutputStream());
            response.flushBuffer();
        } catch (IOException ex) {
            throw new UiFrameworkException("Error trying to write file content to response", ex);
        }
        return null;
    } catch (PageAction action) {
        throw new RuntimeException("Not Yet Implemented: " + action.getClass(), action);
    } catch (RuntimeException ex) {
        // special-case if this is due to the user not being logged in
        APIAuthenticationException authEx = ExceptionUtil.findExceptionInChain(ex,
                APIAuthenticationException.class);
        if (authEx != null) {
            throw authEx;
        }

        // The following should go in an @ExceptionHandler. I tried this, and it isn't getting invoked for some reason.
        // And it's not worth debugging that.

        StringWriter sw = new StringWriter();
        ex.printStackTrace(new PrintWriter(sw));
        model.addAttribute("fullStacktrace", sw.toString());

        Throwable t = ex;
        while (t.getCause() != null && !t.equals(t.getCause()))
            t = t.getCause();
        sw = new StringWriter();
        t.printStackTrace(new PrintWriter(sw));
        model.addAttribute("rootStacktrace", sw.toString());

        return "/module/uiframework/uiError";
    }
}