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:io.knotx.repository.impl.FilesystemRepositoryConnectorProxyImpl.java

private ClientResponse processError(Throwable error) {
    HttpResponseStatus statusCode;//  www . j  av a2  s .  c om
    if (error.getCause().getClass().equals(NoSuchFileException.class)) {
        statusCode = HttpResponseStatus.NOT_FOUND;
    } else {
        statusCode = HttpResponseStatus.INTERNAL_SERVER_ERROR;
    }
    return new ClientResponse().setStatusCode(statusCode.code());
}

From source file:Main.java

private static String getCrashReport(Throwable e, Context application) {

    StringBuffer body = new StringBuffer();
    body.append("Timestamp: " + new Date().toString());
    body.append("\n** Crash Report **\n");
    try {/*from  ww  w.j  av a2 s.  c o m*/
        PackageInfo pi = application.getPackageManager().getPackageInfo(application.getPackageName(), 0);
        body.append("Package Name: ").append(pi.packageName).append("\n");
        body.append("Package Version: ").append(pi.versionCode).append("\n");
        body.append("Phone Model: ").append(android.os.Build.MODEL).append("\n");
        body.append("Phone Manufacturer: ").append(android.os.Build.MANUFACTURER).append("\n");
        body.append("Android Version:").append(android.os.Build.VERSION.RELEASE).append("\n");
    } catch (NameNotFoundException e1) {
    }

    StringWriter stack = new StringWriter();
    PrintWriter writer = new PrintWriter(stack);
    e.printStackTrace(writer);

    body.append("\n\nStacktrace:\n\n");
    body.append(stack.toString()).append("\n");

    if (e.getCause() != null) {
        Throwable cause = e.getCause();
        stack = new StringWriter();
        writer = new PrintWriter(stack);
        cause.printStackTrace(writer);

        body.append("\n\nCause Stacktrace:\n\n");
        body.append(stack.toString()).append("\n");
    }

    body.append("** Crash Report **\n");
    return body.toString();
}

From source file:org.duracloud.duradmin.control.ContentItemDownloadController.java

@RequestMapping(value = "/download/contentItem", method = RequestMethod.GET)
public ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    String storeId = request.getParameter("storeID");
    if (storeId == null) {
        storeId = request.getParameter("storeId");
    }//from  w ww  . j  a  va2  s  .  c o  m

    if (storeId == null) {
        storeId = controllerSupport.getContentStoreManager().getPrimaryContentStore().getStoreId();
    }

    String spaceId = request.getParameter("spaceId");
    String contentId = request.getParameter("contentId");
    String attachment = request.getParameter("attachment");

    if (Boolean.valueOf(attachment)) {
        StringBuffer contentDisposition = new StringBuffer();
        contentDisposition.append("attachment;");
        contentDisposition.append("filename=\"");
        contentDisposition.append(contentId);
        contentDisposition.append("\"");
        response.setHeader(CONTENT_DISPOSITION_HEADER, contentDisposition.toString());
    }

    ContentStore store = controllerSupport.getContentStoreManager().getContentStore(storeId);
    try {
        SpaceUtil.streamContent(store, response, spaceId, contentId);

    } catch (ContentStoreException ex) {
        if (response.containsHeader(CONTENT_DISPOSITION_HEADER)) {
            response.setHeader(CONTENT_DISPOSITION_HEADER, null);
        }

        if (ex instanceof ContentStateException) {
            response.setStatus(HttpStatus.SC_CONFLICT);
        } else if (ex instanceof UnauthorizedException) {
            response.setStatus(HttpStatus.SC_UNAUTHORIZED);
        }

        Throwable t = ex;
        if (t.getCause() != null) {
            t = ex.getCause();
        }
        response.getWriter().println(t.getMessage());
    }

    return null;
}

From source file:org.terracotta.management.cli.rest.AbstractHttpCommand.java

protected String getRootCauseMessage(Throwable t) {
    if (t.getCause() == null || t.getCause() == t) {
        return t.getMessage();
    }/* ww  w.  ja  va2  s .  c om*/
    return getRootCauseMessage(t.getCause());
}

From source file:com.p000ison.dev.simpleclans2.exceptions.handling.ExceptionReport.java

public JSONObject getJSONObject() {
    JSONObject report = new JSONObject();
    report.put("plugin", name);
    report.put("version", version);
    report.put("date", date);
    report.put("exception_class", thrown.getClass().getName());
    report.put("message", thrown.getMessage());
    report.put("exception", buildThrowableJSON(thrown));
    StringBuilder plugins = new StringBuilder().append('[');
    for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
        plugins.append(plugin).append(',');
    }/*from  w ww.j a va 2s  .c  om*/
    plugins.deleteCharAt(plugins.length() - 1).append(']');
    report.put("plugins", plugins.toString());
    report.put("bukkit_version", Bukkit.getBukkitVersion());
    report.put("java_version", getProperty("java.version"));
    report.put("os_arch", getProperty("os.arch"));
    report.put("os_name", getProperty("os.name"));
    report.put("os_version", getProperty("os.version"));

    if (email != null) {
        report.put("email", email);
    }

    JSONArray causes = new JSONArray();

    Throwable cause = thrown;

    while ((cause = cause.getCause()) != null) {
        causes.add(buildThrowableJSON(cause));
    }

    report.put("causes", causes);
    return report;
}

From source file:com.seer.datacruncher.utils.generic.CommonUtils.java

public static String getExceptionMessage(Exception ex) {
    String msg = ex.getMessage();
    if (msg != null) {
        return msg;
    } else {// ww w.  ja v a  2s .  c  o  m
        try {
            msg = "";
            StackTraceElement[] trace = ex.getStackTrace();
            Throwable e1 = ex.getCause();
            if (e1 != null) {
                for (int i = 0; i < trace.length; i++) {
                    if (e1 != null) {
                        msg = e1.getMessage();
                        if (msg != null) {
                            System.out.println(msg);
                            break;
                        } else {
                            e1 = e1.getCause();
                        }
                    }
                }
            }
            return msg;
        } catch (Exception e) {
            return msg;
        }
    }
}

From source file:io.kahu.hawaii.util.spring.HawaiiControllerExceptionHandler.java

@ExceptionHandler(UndeclaredThrowableException.class)
@ResponseBody//from  w w  w  . j a  v  a  2  s. co m
public ResponseEntity<String> catchUndeclaredThrowable(Throwable throwable) {
    Throwable cause = throwable.getCause();
    if (cause instanceof HawaiiException) {
        return catchHawaiiException((HawaiiException) cause);
    }
    return handleException(throwable, 500, new JSONObject());
}

From source file:org.biokoframework.http.exception.impl.ExceptionResponseBuilderImpl.java

private int chooseStatusCode(Throwable cause) {
    while (cause != null && cause != cause.getCause()) {
        if (cause instanceof BiokoException) {
            Integer code = fStatusCodesMap.get(cause.getClass());
            if (code != null) {
                return code;
            }/*from  w  w w .  j a  v a  2 s .  co m*/
        }
        cause = cause.getCause();
    }
    return HttpStatus.SC_INTERNAL_SERVER_ERROR;
}

From source file:org.apache.camel.component.dns.DNSLookupEndpointSpringTest.java

@Test
public void testDNSWithEmptyNameHeader() throws Exception {
    _resultEndpoint.expectedMessageCount(0);
    try {/*from   w  w w.j  a v a  2 s  .  c o m*/
        _template.sendBodyAndHeader("hello", "dns.name", "");
    } catch (Throwable t) {
        t.printStackTrace();
        assertTrue(t.toString(), t.getCause() instanceof IllegalArgumentException);
    }
    _resultEndpoint.assertIsSatisfied();
}

From source file:br.com.manish.ahy.web.BaseJSF.java

protected void treat(Exception e) {

    OopsException oe = null;//from  w  w w  .j a  v  a 2 s  . co m
    if (e instanceof OopsException) {
        oe = (OopsException) e;
    } else if (e.getCause() instanceof OopsException) {
        oe = (OopsException) e.getCause();
    }

    String msg = "";
    if (oe != null) {
        msg = oe.getMessage();
        msg = formatMsg(msg, oe.getAdditionalInformation());
        log.warn("OopsException: " + oe.getMessage() + " - " + msg);
    } else {
        Throwable tmp = e;
        msg += tmp.getMessage() + "\n";
        while (tmp.getCause() != null) {
            msg += tmp.getMessage() + "\n";
            tmp = tmp.getCause();
        }
        logException(e);
    }

    FacesContext.getCurrentInstance().addMessage(null,
            new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, null));

}