Example usage for java.lang Throwable getMessage

List of usage examples for java.lang Throwable getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:hudson.Util.java

/**
 * Extracts the Win32 error message from {@link Throwable} if possible.
 *
 * @return/*from   w  w w .ja  v  a2 s  .  c  o  m*/
 *      null if there seems to be no error code or if the platform is not Win32.
 */
public static String getWin32ErrorMessage(Throwable e) {
    String msg = e.getMessage();
    if (msg != null) {
        Matcher m = errorCodeParser.matcher(msg);
        if (m.matches()) {
            try {
                ResourceBundle rb = ResourceBundle.getBundle("/hudson/win32errors");
                return rb.getString("error" + m.group(1));
            } catch (Exception _) {
                // silently recover from resource related failures
            }
        }
    }

    if (e.getCause() != null)
        return getWin32ErrorMessage(e.getCause());
    return null; // no message
}

From source file:com.qwazr.server.ServerException.java

public static ServerException of(String message, final Throwable throwable) {
    if (throwable instanceof ServerException)
        return (ServerException) throwable;

    int status = 500;

    final int serverExceptionPos = ExceptionUtils.indexOfType(throwable, ServerException.class);
    if (serverExceptionPos != -1)
        return (ServerException) ExceptionUtils.getThrowableList(throwable).get(serverExceptionPos);

    final int webApplicationExceptionPos = ExceptionUtils.indexOfType(throwable, WebApplicationException.class);
    if (webApplicationExceptionPos != -1)
        status = ((WebApplicationException) ExceptionUtils.getThrowableList(throwable)
                .get(webApplicationExceptionPos)).getResponse().getStatus();

    if (StringUtils.isBlank(message)) {
        message = throwable.getMessage();
        if (StringUtils.isBlank(message))
            message = ExceptionUtils.getRootCauseMessage(throwable);
        if (StringUtils.isBlank(message))
            message = "Internal server error";
    }//  www .  j a  v  a  2  s . c  om

    return new ServerException(status, message, throwable);
}

From source file:org.jruby.rack.mock.WebUtils.java

/**
 * Expose the Servlet spec's error attributes as {@link javax.servlet.http.HttpServletRequest}
 * attributes under the keys defined in the Servlet 2.3 specification, for error pages that
 * are rendered directly rather than through the Servlet container's error page resolution:
 * {@code javax.servlet.error.status_code},
 * {@code javax.servlet.error.exception_type},
 * {@code javax.servlet.error.message},/*from w  w  w .  j a  v a2  s  .c  om*/
 * {@code javax.servlet.error.exception},
 * {@code javax.servlet.error.request_uri},
 * {@code javax.servlet.error.servlet_name}.
 * <p>Does not override values if already present, to respect attribute values
 * that have been exposed explicitly before.
 * <p>Exposes status code 200 by default. Set the "javax.servlet.error.status_code"
 * attribute explicitly (before or after) in order to expose a different status code.
 * @param request current servlet request
 * @param ex the exception encountered
 * @param servletName the name of the offending servlet
 */
public static void exposeErrorRequestAttributes(HttpServletRequest request, Throwable ex, String servletName) {
    exposeRequestAttributeIfNotPresent(request, ERROR_STATUS_CODE_ATTRIBUTE, HttpServletResponse.SC_OK);
    exposeRequestAttributeIfNotPresent(request, ERROR_EXCEPTION_TYPE_ATTRIBUTE, ex.getClass());
    exposeRequestAttributeIfNotPresent(request, ERROR_MESSAGE_ATTRIBUTE, ex.getMessage());
    exposeRequestAttributeIfNotPresent(request, ERROR_EXCEPTION_ATTRIBUTE, ex);
    exposeRequestAttributeIfNotPresent(request, ERROR_REQUEST_URI_ATTRIBUTE, request.getRequestURI());
    exposeRequestAttributeIfNotPresent(request, ERROR_SERVLET_NAME_ATTRIBUTE, servletName);
}

From source file:de.huxhorn.lilith.Lilith.java

@SuppressWarnings({ "ThrowableResultOfMethodCallIgnored" })
private static void appendStatus(StringBuilder builder, Status status, int indent) {
    int levelCode = status.getLevel();
    appendIndent(builder, indent);/*from   www .  j a  v a2s  .c  om*/
    if (levelCode >= 0 && levelCode < STATUS_TEXT.length) {
        builder.append(STATUS_TEXT[levelCode]);
    }
    builder.append(status.getMessage()).append('\n');
    Throwable t = status.getThrowable();
    while (t != null) {
        appendIndent(builder, indent + 1);
        builder.append(t.getClass().getName());
        String message = t.getMessage();
        if (message != null) {
            builder.append(": ").append(message);
        }
        builder.append('\n');
        // probably check for causes, too
        t = t.getCause();
    }
    if (status.hasChildren()) {
        Iterator<Status> children = status.iterator();
        while (children.hasNext()) {
            appendStatus(builder, children.next(), indent + 1);
        }
    }
}

From source file:at.plechinger.scrapeql.cli.ScrapeQLShell.java

public ScrapeQLShell(String[] args) {
    try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
        Query query = parser.parse(CharStreams.toString(reader));

        Map<String, Object> output = query.execute();
        ObjectMapper mapper = new ObjectMapper();
        mapper.enable(SerializationFeature.INDENT_OUTPUT);

        String outputString = mapper.writeValueAsString(output);

        System.out.println(outputString);

    } catch (Throwable e) {
        System.out.println(e.getMessage());
    }/* w ww  .  j a va 2 s  .co m*/
}

From source file:gov.nih.nci.cagrid.portal.portlet.workflow.WorkflowException.java

public WorkflowException(Throwable cause) {
    super(cause.getMessage(), cause);
}

From source file:uk.co.jassoft.jms.listener.JmsErrorHandler.java

@Override
public void handleError(Throwable thrwbl) {
    LOG.error(thrwbl.getMessage(), thrwbl);
}

From source file:io.pivotal.cf.servicebroker.KafkaBrokerException.java

public KafkaBrokerException(Throwable cause) {
    this(cause.getMessage(), cause);

}

From source file:com.evolveum.midpoint.test.IntegrationTestTools.java

public static boolean hasInMessageRecursive(Throwable e, String substring) {
    if (e.getMessage().contains(substring)) {
        return true;
    }// w  ww . j  a v  a2 s  . c om
    if (e.getCause() != null) {
        return hasInMessageRecursive(e.getCause(), substring);
    }
    return false;
}

From source file:com.sap.nwcloudmanager.api.DeployAPI.java

public static void listApps(final ListAppsResponseHandler handler) {

    NetWeaverCloudConfig config = NetWeaverCloudConfig.getInstance();
    getHttpClient().setBasicAuth(config.getUsername(), config.getPassword());
    getHttpClient().get("https://" + config.getHost() + "/deploy/" + config.getAccount() + "/appliances", null,
            new JsonHttpResponseHandler() {

                @Override//from www .  ja  va2s.com
                protected void handleFailureMessage(Throwable arg0, String arg1) {
                    handler.onFailure(arg0, arg1);
                }

                @Override
                public void onSuccess(JSONObject json) {
                    if (json.has("appliances")) {
                        String appliances;
                        try {
                            appliances = (String) json.getString("appliances");
                            handler.onSuccess(appliances.split(","));
                        } catch (JSONException e) {
                            Log.e(e.getMessage());
                        }
                    }
                }

                @Override
                public void onFailure(Throwable arg0) {
                    handler.onFailure(arg0, arg0.getMessage());
                }

            });
}