List of usage examples for java.lang Throwable getStackTrace
public StackTraceElement[] getStackTrace()
From source file:hm.binkley.util.XPropsConverter.java
private static <T, E extends Exception> Conversion<T, E> invokeConstructor(final Class<T> token) throws NoSuchMethodError { try {// w w w. j av a2s . c o m final Constructor<T> ctor = token.getConstructor(String.class); return value -> { try { return ctor.newInstance(value); } catch (final IllegalAccessException e) { final IllegalAccessError x = new IllegalAccessError(e.getMessage()); x.setStackTrace(e.getStackTrace()); throw x; } catch (final InvocationTargetException e) { final Throwable root = getRootCause(e); final RuntimeException x = new RuntimeException(root); x.setStackTrace(root.getStackTrace()); throw x; } catch (final InstantiationException e) { final InstantiationError x = new InstantiationError(e.getMessage()); x.setStackTrace(e.getStackTrace()); throw x; } }; } catch (final NoSuchMethodException ignored) { return null; } }
From source file:org.squale.squaleweb.util.ExceptionWrapper.java
/** * Extraction des informations d'une exception * //from w w w .j av a2 s. c o m * @param pException exception * @param pw writer */ private static void dumpException(Throwable pException, PrintWriter pw) { pw.println("<BR><BR><B>Error Message: </B>" + pException.getMessage() + "<BR>"); pw.println("<B>Error Stack: </B><BR>"); pw.println(pException.getClass().getName() + ": " + pException.getMessage()); StackTraceElement[] elements = pException.getStackTrace(); for (int i = 0; i < elements.length; i++) { pw.println("<BR> " + elements[i]); } }
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 www . j a v a 2 s .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:mSearch.tool.Log.java
private static void fehlermeldung_(int fehlerNummer, Exception ex, String[] texte) { final Throwable t = new Throwable(); final StackTraceElement methodCaller = t.getStackTrace()[2]; final String klasse = methodCaller.getClassName() + "." + methodCaller.getMethodName(); String kl;/* w w w . j a v a 2s . c o m*/ try { kl = klasse; while (kl.contains(".")) { if (Character.isUpperCase(kl.charAt(0))) { break; } else { kl = kl.substring(kl.indexOf(".") + 1); } } } catch (Exception ignored) { kl = klasse; } addFehlerNummer(fehlerNummer, kl, ex != null); if (ex != null || Config.debug) { // Exceptions immer ausgeben resetProgress(); String x, z; if (ex != null) { x = "!"; } else { x = "="; } z = "*"; logList.add(x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x); try { // Stacktrace try (StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw)) { if (ex != null) { ex.printStackTrace(pw); } pw.flush(); sw.flush(); logList.add(sw.toString()); } } catch (Exception ignored) { } logList.add(z + " Fehlernr: " + fehlerNummer); if (ex != null) { logList.add(z + " Exception: " + ex.getMessage()); } logList.add(z + " " + FEHLER + kl); for (String aTexte : texte) { logList.add(z + " " + aTexte); } logList.add(""); printLog(); } }
From source file:com.cloud.utils.StringUtils.java
public static String getExceptionStackInfo(final Throwable e) { final StringBuffer sb = new StringBuffer(); sb.append(e.toString()).append("\n"); final StackTraceElement[] elemnents = e.getStackTrace(); for (final StackTraceElement element : elemnents) { sb.append(element.getClassName()).append("."); sb.append(element.getMethodName()).append("("); sb.append(element.getFileName()).append(":"); sb.append(element.getLineNumber()).append(")"); sb.append("\n"); }/* w w w . j av a 2 s . co m*/ return sb.toString(); }
From source file:org.netbeans.jpa.modeler.collaborate.issues.ExceptionUtils.java
public static void printStackTrace(String errorMessage, final Throwable t, final ModelerFile file) { t.printStackTrace();//from ww w .j a va 2s. com 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); }); t.printStackTrace(); }
From source file:com.codelanx.codelanxlib.util.exception.Exceptions.java
/** * Recursive method for appending {@link Throwable] causes that are appended * to a {@link Throwable}/*ww w . jav a2 s . c om*/ * * @since 0.1.0 * @version 0.1.0 * * @param sb The {@link StringBuilder} being appended to * @param t The {@link Throwable} root * @param causedTrace An array of already visited stack nodes */ private static void readableStackTraceAsCause(StringBuilder sb, Throwable t, StackTraceElement[] causedTrace) { // Compute number of frames in common between previous and caused StackTraceElement[] trace = t.getStackTrace(); int m = trace.length - 1; int n = causedTrace.length - 1; while (m >= 0 && n >= 0 && trace[m].equals(causedTrace[n])) { m--; n--; } int common = trace.length - 1 - m; sb.append("Caused by: ").append(t).append('\n'); for (int i = 0; i <= m; i++) { sb.append("\tat ").append(trace[i]).append('\n'); } if (common != 0) { sb.append("\t... ").append(common).append(" more\n"); } if (t.getCause() != null) { Exceptions.readableStackTraceAsCause(sb, t.getCause(), trace); } }
From source file:com.quinsoft.zeidon.ZeidonException.java
/** * Wraps 't' with a ZeidonException and changes the call stack for the ZeidonException to * match 't'. This is mostly used to re-throw checked exceptions as unchecked ones. * * @param t//from w w w . j a v a 2s. c o m * @return */ public static ZeidonException wrapException(Throwable t) { // If this is already a ZeidonException then we don't need to wrap it. if (t instanceof ZeidonException) return (ZeidonException) t; ZeidonException ze = new ZeidonException(t, t.toString()); ze.setStackTrace(t.getStackTrace()); return ze; }
From source file:apm.common.utils.StringUtils.java
public static String traceExceptionMessage(Object source, Throwable e) { String newLine = System.getProperty("line.separator"); StringBuffer exceptionInfo_sb = new StringBuffer(source.toString()); exceptionInfo_sb.append(newLine + e.toString()); StackTraceElement[] trace = e.getStackTrace(); for (int i = 0; i < trace.length; i++) { exceptionInfo_sb.append(newLine + "\tat " + trace[i]); }/*from w w w.j a v a2 s . co m*/ return exceptionInfo_sb.toString(); }
From source file:edu.uci.ics.asterix.result.ResultUtils.java
/** * Extract the meaningful part of a stack trace: * a. the causes in the stack trace hierarchy * b. the top exception for each cause//from w w w .j a v a 2 s . c om * * @param e * @return the contacted message containing a and b. */ private static String extractErrorSummary(Throwable e) { StringBuilder errorMessageBuilder = new StringBuilder(); Throwable cause = e; errorMessageBuilder.append(cause.getLocalizedMessage()); while (cause != null) { StackTraceElement[] stackTraceElements = cause.getStackTrace(); errorMessageBuilder .append(stackTraceElements.length > 0 ? "\n caused by: " + stackTraceElements[0] : ""); cause = cause.getCause(); } return errorMessageBuilder.toString(); }