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: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);
        }/* w  w w.ja  v  a2  s  . co  m*/
    }
    Throwable cause = e.getCause();
    if (cause != null) {
        return determineMessage(cause);
    }
    return e.getMessage();
}

From source file:ThreadLog.java

static String _createLogMessage(String msg, Object arg, int level, String threadName) {
    StringBuilder logMsg = new StringBuilder(128);

    logMsg.append(_formatter.format(new Date()));
    if (threadName != null) {
        logMsg.append(" [");
        logMsg.append(threadName);//from w  w w  .j  ava2 s.  c  o m
        logMsg.append("]");
    }
    logMsg.append(" [");
    logMsg.append(_levelNames[level]);
    logMsg.append("] ");

    logMsg.append(msg);
    if (arg != null) {
        logMsg.append(": ");

        if (arg instanceof Throwable) {
            Throwable throwable = (Throwable) arg;
            logMsg.append(throwable.getMessage());
            logMsg.append(LINE_SEPARATOR);

            java.io.StringWriter stackTrace = new java.io.StringWriter();
            java.io.PrintWriter pw = new java.io.PrintWriter(stackTrace);
            throwable.printStackTrace(pw);
            logMsg.append(stackTrace.toString());
        } else {
            String argString = arg.toString();
            if (argString.contains("\n") || argString.contains("\r")) {
                // argument formatted with newlines, do not append on same line
                logMsg.append(LINE_SEPARATOR);
            }
            logMsg.append(argString);
        }
    }
    logMsg.append(LINE_SEPARATOR);

    return logMsg.toString();
}

From source file:com.qpark.eip.core.ToString.java

private static String getStackTrace(final Throwable t, final boolean isCause) {
    StringBuffer sb = new StringBuffer(1024);
    if (isCause) {
        sb.append("Caused by: ");
    }//  w ww .  j  av a  2s .c  om
    sb.append(t.getClass().getName()).append(": ").append(t.getMessage()).append("\n");
    StackTraceElement[] stack = t.getStackTrace();
    int classNameLines = 0;
    int classNameLinesMax = 3;
    boolean printDots = false;
    boolean firstLine = true;
    for (StackTraceElement elem : stack) {
        if (firstLine || elem.getClassName().startsWith(CLASSNAME) && classNameLines <= classNameLinesMax) {
            sb.append("\tat ").append(elem.toString()).append("\n");
            classNameLines++;
            firstLine = false;
            printDots = false;
        } else {
            if (!printDots) {
                sb.append("\tat ...\n");
                printDots = true;
            }
            classNameLines = 0;
        }
    }
    Throwable cause = t.getCause();
    if (cause != null) {
        sb.append(getStackTrace(cause, true));
    }
    return sb.toString();
}

From source file:com.salesforce.ide.core.internal.utils.ForceExceptionUtils.java

public static String getExceptionMessage(Throwable th) {
    if (th instanceof ApiFault) {
        return ((ApiFault) th).getExceptionMessage();
    } else if (th instanceof ForceException) {
        return ((ForceException) th).getExceptionMessage();
    } else {/*from  w  w w .  ja  v a2s. c o m*/
        return th.getMessage();
    }
}

From source file:net.sf.jabref.importer.OpenDatabaseAction.java

/**
 * Load database (bib-file) or, if there exists, a newer autosave version, unless the flag is set to ignore the autosave
 *
 * @param name Name of the bib-file to open
 * @param ignoreAutosave true if autosave version of the file should be ignored
 * @return ParserResult which never is null
 *///  w  w w.j  a  v  a2 s .  co m

public static ParserResult loadDatabaseOrAutoSave(String name, boolean ignoreAutosave) {
    // String in OpenDatabaseAction.java
    LOGGER.info("Opening: " + name);
    File file = new File(name);
    if (!file.exists()) {
        ParserResult pr = new ParserResult(null, null, null);
        pr.setFile(file);
        pr.setInvalid(true);
        LOGGER.error(Localization.lang("Error") + ": " + Localization.lang("File not found"));
        return pr;

    }
    try {

        if (!ignoreAutosave) {
            boolean autoSaveFound = AutoSaveManager.newerAutoSaveExists(file);
            if (autoSaveFound) {
                // We have found a newer autosave. Make a note of this, so it can be
                // handled after startup:
                ParserResult postp = new ParserResult(null, null, null);
                postp.setPostponedAutosaveFound(true);
                postp.setFile(file);
                return postp;
            }
        }

        if (!FileBasedLock.waitForFileLock(file.toPath(), 10)) {
            LOGGER.error(Localization.lang("Error opening file") + " '" + name + "'. "
                    + "File is locked by another JabRef instance.");
            return ParserResult.getNullResult();
        }

        Charset encoding = Globals.prefs.getDefaultEncoding();
        ParserResult pr = OpenDatabaseAction.loadDatabase(file, encoding);
        pr.setFile(file);
        if (pr.hasWarnings()) {
            for (String aWarn : pr.warnings()) {
                LOGGER.warn(aWarn);
            }
        }
        return pr;
    } catch (Throwable ex) {
        ParserResult pr = new ParserResult(null, null, null);
        pr.setFile(file);
        pr.setInvalid(true);
        pr.setErrorMessage(ex.getMessage());
        LOGGER.info("Problem opening .bib-file", ex);
        return pr;
    }

}

From source file:net.sf.jabb.util.db.ConnectionUtility.java

/**
 * ????DataSourceProvider//w  w  w  .  j  a va2 s.c  o  m
 */
protected static void setupDataSourceProviders() {
    List<String> providerProperties = new LinkedList<String>();
    for (Object key : configuration.keySet()) {
        String keyName = (String) key;
        if (keyName.startsWith(PROVIDER_PROPERTY_NAME)) {
            providerProperties.add(keyName);
        }
    }

    dataSourceProviders = new HashMap<String, DataSourceProvider>();
    for (String keyName : providerProperties) {
        String providerName = keyName.substring(PROVIDER_PROPERTY_NAME.length(), keyName.length());
        String providerClassName = configuration.getProperty(keyName);
        configuration.remove(keyName);
        DataSourceProvider dsp = null;
        try {
            dsp = (DataSourceProvider) Class.forName(providerClassName).newInstance();
            dataSourceProviders.put(providerName, dsp);
        } catch (Throwable t) {
            if (t instanceof NoClassDefFoundError) {
                log.debug("DataSourceProvider not initialized for '" + providerName
                        + "' because the provider class was not found: " + t.getMessage());
            } else {
                log.error("Cannot instantiate DataSourceProvider for '" + providerName + "': "
                        + providerClassName, t);
            }
        }
    }
}

From source file:net.sf.firemox.xml.XmlTbs.java

/**
 * Writes the card identified by the given card XML description file name in
 * the given directory to the given OutputStream.
 * //  w w  w. ja  va2s  . c  o  m
 * @param currentDir
 *          the directory path to find the card XML description file name
 * @param out
 *          the OutputStream to write the identified card to
 * @param cardFile
 *          the card XML description file name
 */
private static void writeCard(String currentDir, OutputStream out, String cardFile) {
    try {
        XmlConfiguration.parseCard(cardFile, currentDir, out);
    } catch (Throwable e) {
        if (e instanceof StackOverflowError) {
            throw new InternalError(
                    "StackOverflowError writting card, may be you use some recursive actions reference");
        }
        throw new InternalError(e.getMessage());
    }
}

From source file:com.myJava.util.Util.java

public static void logThreadInformations(String header, Thread thread) {
    try {/*from w  w w.j  a  va2s  . c  o  m*/
        StackTraceElement[] elements = thread.getStackTrace();
        String thd;
        if (header != null) {
            thd = header + "\n";
        } else {
            thd = "";
        }
        thd += "Thread dump :";
        if (elements != null) {
            for (int i = 0; i < elements.length; i++) {
                thd += "\n";
                if (i != 0) {
                    thd += "at ";
                }
                thd += elements[i].getClassName() + "." + elements[i].getMethodName() + " (Line "
                        + elements[i].getLineNumber() + ")";
            }
        }
        Logger.defaultLogger().fine(thd);
    } catch (Throwable e) {
        Logger.defaultLogger().warn(e.getMessage());
    }
}

From source file:edu.utah.further.ds.impl.advice.QpMonitorAdvice.java

/**
 * @param throwable/* ww w .  j av a  2 s  .c  o m*/
 * @return
 */
private static String getExceptionAsString(final Throwable throwable) {
    String exceptionString = throwable.toString();
    if (ReflectionUtil.instanceOf(throwable, ApplicationException.class)) {
        final ApplicationException error = (ApplicationException) throwable;
        if (error.getCode() != null) {
            if (error.getCode().isRecoverable()) {
                exceptionString = throwable.getClass() + ": " + throwable.getMessage();
            }
        }

    }
    return exceptionString;
}

From source file:com.microsoft.azure.hdinsight.jobs.JobViewDummyHttpServer.java

public synchronized static void initlize() {
    if (isEnabled) {
        return;/* w ww.  j a va2  s. c  om*/
    }
    try {
        server = HttpServer.create(new InetSocketAddress(PORT), 10);
        server.createContext("/clusters/", new HttpHandler() {
            @Override
            public void handle(final HttpExchange httpExchange) throws IOException {
                final RequestDetail requestDetail = getRequestDetail(httpExchange.getRequestURI());

                if (requestDetail == null) {
                    return;
                }

                IClusterDetail clusterDetail = requestDetail.getClusterDetail();

                if (clusterDetail == null) {
                    return;
                }

                String preUrl = "";
                switch (requestDetail.getApiType()) {
                case YarnHistory:
                    preUrl = yarnHistoryUrl;
                    break;
                case YarnRest:
                    preUrl = yarnPreRestUrl;
                    break;
                case LivyBatchesRest:
                    preUrl = LivyBatchesRestUrl;
                    break;
                default:
                    preUrl = sparkPreRestUrl;
                }

                String queryUrl = String.format(preUrl, clusterDetail.getName()) + requestDetail.getRestUrl();

                if (requestDetail.getApiType() == RequestDetail.APIType.YarnHistory) {
                    if (queryUrl.endsWith("stderr")) {
                        queryUrl = queryUrl + "?start=0";
                    }

                    TaskExecutor
                            .submit(new YarnHistoryTask(clusterDetail, queryUrl, new FutureCallback<String>() {
                                @Override
                                public void onSuccess(String str) {
                                    httpExchange.getResponseHeaders().add("Access-Control-Allow-Origin", "*");
                                    try {
                                        // work around of get job result
                                        //TODO: get job result by REST API
                                        Document doc = Jsoup.parse(str);
                                        Elements contentElements = doc.getElementsByClass("content");
                                        if (contentElements.size() == 1) {
                                            Elements elements = contentElements.get(0).getElementsByTag("pre");
                                            if (elements.size() == 1) {
                                                str = elements.get(0).html();
                                            }
                                        }

                                        httpExchange.sendResponseHeaders(200, str.length());
                                        OutputStream stream = httpExchange.getResponseBody();
                                        stream.write(str.getBytes());
                                        stream.close();
                                    } catch (IOException e) {
                                        LOGGER.error("Get job history error", e);
                                    }
                                }

                                @Override
                                public void onFailure(Throwable throwable) {
                                    httpExchange.getResponseHeaders().add("Access-Control-Allow-Origin", "*");
                                    try {
                                        String str = throwable.getMessage();
                                        httpExchange.sendResponseHeaders(200, str.length());
                                        OutputStream stream = httpExchange.getResponseBody();
                                        stream.write(str.getBytes());
                                        stream.close();
                                    } catch (Exception e) {
                                        LOGGER.error("Get job history error", e);
                                    }
                                }
                            }));
                } else if (requestDetail.getApiType() == RequestDetail.APIType.LivyBatchesRest) {
                    TaskExecutor.submit(new LivyTask(clusterDetail, queryUrl, new FutureCallback<String>() {
                        @Override
                        public void onSuccess(String str) {
                            httpExchange.getResponseHeaders().add("Access-Control-Allow-Origin", "*");
                            try {
                                String applicationId = requestDetail.getProperty("applicationId");
                                if (applicationId != null) {
                                    str = JobUtils.getJobInformation(str, applicationId);
                                }

                                httpExchange.sendResponseHeaders(200, str.length());
                                OutputStream stream = httpExchange.getResponseBody();
                                stream.write(str.getBytes());
                                stream.close();
                            } catch (IOException e) {
                                LOGGER.error("Get job history error", e);
                            }
                        }

                        @Override
                        public void onFailure(Throwable throwable) {
                            httpExchange.getResponseHeaders().add("Access-Control-Allow-Origin", "*");
                            try {
                                String str = throwable.getMessage();
                                httpExchange.sendResponseHeaders(200, str.length());
                                OutputStream stream = httpExchange.getResponseBody();
                                stream.write(str.getBytes());
                                stream.close();
                            } catch (Exception e) {
                                LOGGER.error("Get job history error", e);
                            }
                        }
                    }));

                } else {
                    TaskExecutor.submit(new RestTask(clusterDetail, queryUrl, new FutureCallback<String>() {
                        @Override
                        public void onSuccess(String str) {
                            httpExchange.getResponseHeaders().add("Access-Control-Allow-Origin", "*");
                            try {
                                httpExchange.sendResponseHeaders(200, str.length());
                                OutputStream stream = httpExchange.getResponseBody();
                                stream.write(str.getBytes());
                                stream.close();
                            } catch (IOException e) {
                                LOGGER.error("Get job history error", e);
                            }
                        }

                        @Override
                        public void onFailure(Throwable throwable) {
                            httpExchange.getResponseHeaders().add("Access-Control-Allow-Origin", "*");
                            try {
                                String str = throwable.getMessage();
                                httpExchange.sendResponseHeaders(200, str.length());
                                OutputStream stream = httpExchange.getResponseBody();
                                stream.write(str.getBytes());
                                stream.close();
                            } catch (Exception e) {
                                LOGGER.error("Get job history error", e);
                            }
                        }
                    }));
                }

            }
        });

        executorService = Executors.newFixedThreadPool(NO_OF_THREADS);
        server.setExecutor(executorService);
        server.start();
        isEnabled = true;
    } catch (IOException e) {
        LOGGER.error("Get job history error", e);
    }
}