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:ratpack.sep.ActionResult.java

/**
 * Creates an error result, with the given exception.
 * <p>//  w  w w. java 2 s .c o  m
 * The message of the given exception will be used as the message of the result
 * @param error an exception thrown during action exception
 * @param <T> a type of accompanying data
 * @return an failed result, with the given error
 */
public static <T> ActionResult<T> error(Throwable error) {
    return new ActionResult<>(error.toString(), error.getMessage(), error, null);
}

From source file:com.espertech.esper.epl.script.mvel.MVELHelper.java

private static ExprValidationException handleTargetException(String scriptName, InvocationTargetException ex) {
    Throwable mvelException = ex.getTargetException();
    String message = "Exception compiling MVEL script '" + scriptName + "': " + mvelException.getMessage();
    log.info(message, mvelException);/*from  ww  w  .jav  a  2s . c  o m*/
    return new ExprValidationException(message, mvelException);
}

From source file:com.sharneng.io.IOUtils.java

/**
 * Quietly close a {@linkplain java.io.InputStream} without throwing any exception. Exceptions will be logged as
 * error if the <code>logError</code> is <code>true</code>.
 * //from  w w  w.  j  a  v  a  2  s. c  om
 * @param in
 *            the input stream to close
 * @param logError
 *            true to log exception as error
 * @see #close(InputStream)
 * @see #close(OutputStream, boolean)
 */
public static void close(InputStream in, boolean logError) {
    if (in != null) {
        try {
            in.close();
        } catch (Throwable t) {
            if (logError)
                log.error(t.getMessage(), t);
            else
                log.debug(t.getMessage(), t);
        }
    }
}

From source file:com.sharneng.io.IOUtils.java

/**
 * Quietly close a {@linkplain java.io.OutputStream} without throwing any exception. Exceptions will be logged as
 * error if the <code>logError</code> is <code>true</code>.
 * //from ww  w . j a  v a2  s.c o m
 * @param out
 *            the output stream to close
 * @param logError
 *            true to log exception as error
 * @see #close(OutputStream)
 * @see #close(InputStream, boolean)
 */
public static void close(OutputStream out, boolean logError) {
    if (out != null) {
        try {
            out.close();
        } catch (Throwable t) {
            if (logError)
                log.error(t.getMessage(), t);
            else
                log.debug(t.getMessage(), t);
        }
    }
}

From source file:com.github.rnewson.couchdb.lucene.Utils.java

public static String error(final int code, final Throwable t) {
    final StringWriter writer = new StringWriter();
    final PrintWriter printWriter = new PrintWriter(writer);
    if (t.getMessage() != null) {
        printWriter.append(t.getMessage());
        printWriter.append("\n");
    }//  ww  w.j a v a2  s  .c om
    t.printStackTrace(printWriter);
    return new JSONObject().element("code", code).element("body", "<pre>" + writer + "</pre>").toString();
}

From source file:com.netflix.genie.agent.cli.UserConsole.java

/**
 * Load and print the Spring banner (if one is configured) to UserConsole.
 *
 * @param environment the Spring environment
 *///from  w w w .  j  ava2 s. co  m
static void printBanner(final Environment environment) {
    try {
        final String bannerLocation = environment.getProperty(BANNER_LOCATION_SPRING_PROPERTY_KEY);
        if (StringUtils.isNotBlank(bannerLocation)) {
            final ResourceLoader resourceLoader = new DefaultResourceLoader();
            final Resource resource = resourceLoader.getResource(bannerLocation);
            if (resource.exists()) {
                final String banner = StreamUtils.copyToString(resource.getInputStream(),
                        environment.getProperty(BANNER_CHARSET_SPRING_PROPERTY_KEY, Charset.class,
                                StandardCharsets.UTF_8));
                UserConsole.getLogger().info(banner);
            }
        }
    } catch (final Throwable t) {
        System.err.println("Failed to print banner: " + t.getMessage());
        t.printStackTrace(System.err);
    }
}

From source file:net.rim.ejde.internal.legacy.Util.java

static public Workspace getDefaultLegacyWorkspace() {
    Workspace workspace = null;/*  w w w .  ja v  a2 s. co  m*/

    File file = ILegacy.Workspace.getMetaFile();

    try {
        if (!file.exists()) {
            file.getParentFile().mkdirs();
            file.createNewFile();
        }

        workspace = new Workspace(file);

        save(workspace, true);
    } catch (Throwable t) {
        log.error(t.getMessage(), t);
    }

    return workspace;
}

From source file:io.github.jeddict.collaborate.issues.ExceptionUtils.java

public static void printStackTrace(String errorMessage, final Throwable t, final ModelerFile file) {
    t.printStackTrace();//from   w  ww  .  j a va  2s  .c o m
    if (StringUtils.isBlank(errorMessage)) {
        errorMessage = t.getMessage();

        if (StringUtils.isBlank(errorMessage)) {
            if (t.getCause() != null && StringUtils.isNotBlank(t.getCause().getMessage())) {
                errorMessage = t.getCause().getMessage();
            } else if (t.getStackTrace().length > 0) {
                errorMessage = t.getStackTrace()[0].toString();
            }
        }
    }
    final String message = errorMessage;
    LOG.log(Level.ALL, errorMessage, t);
    String content = file != null ? file.getContent() : "";
    SwingUtilities.invokeLater(() -> {
        ExceptionReporterPanel exceptionReporterPanel = new ExceptionReporterPanel(message, t, content);
        exceptionReporterPanel.setVisible(true);
    });
}

From source file:org.robam.xutils.Utils.OtherUtils.java

/**
 *
 */// www. java  2 s .  c  om
public static void trustAllSSLForHttpsURLConnection() {
    // Create a trust manager that does not validate certificate chains
    if (trustAllCerts == null) {
        trustAllCerts = new TrustManager[] { new X509TrustManager() {
            public X509Certificate[] getAcceptedIssuers() {
                return null;
            }

            public void checkClientTrusted(X509Certificate[] certs, String authType) {
            }

            public void checkServerTrusted(X509Certificate[] certs, String authType) {
            }
        } };
    }
    // Install the all-trusting trust manager
    final SSLContext sslContext;
    try {
        sslContext = SSLContext.getInstance("TLS");
        sslContext.init(null, trustAllCerts, null);
        HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
    } catch (Throwable e) {
        LogUtils.e(e.getMessage(), e);
    }
    HttpsURLConnection
            .setDefaultHostnameVerifier(org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
}

From source file:com.machinepublishers.jbrowserdriver.Util.java

static void handleException(Throwable throwable) {
    if (throwable != null) {
        String message = throwable.getMessage();
        if ((throwable instanceof UncheckedExecutionException || throwable instanceof RemoteException)
                && throwable.getCause() != null) {
            throwable = throwable.getCause();
            message = throwable.getMessage();
        }/*w  ww  .  j a v a2  s.c o  m*/
        if (throwable instanceof WebDriverException && throwable instanceof RuntimeException) {
            //Wrap the exception to ensure complete/helpful stack trace info and also preserve the original subtype
            try {
                throwable = throwable.getClass().getConstructor(String.class, Throwable.class)
                        .newInstance(message, throwable);
            } catch (Throwable t) {
                try {
                    throwable = throwable.getClass().getConstructor(Throwable.class).newInstance(throwable);
                } catch (Throwable t2) {
                }
            }
            throw (RuntimeException) throwable;
        }
        throw new WebDriverException(message, throwable);
    }
}