List of usage examples for java.lang Throwable getStackTrace
public StackTraceElement[] getStackTrace()
From source file:com.runwaysdk.logging.RunwayLog.java
public void fatal(Object arg0, Throwable arg1) { try {/* w w w . j a va2 s .c om*/ addSessionIdInfo(); logger.fatal(arg0, arg1); removeSessionIdInfo(); } catch (Throwable e) { System.err.println(e.getLocalizedMessage()); System.err.println(e.getStackTrace()); } }
From source file:org.uiautomation.ios.communication.FailedWebDriverLikeResponse.java
private JSONObject serializeException(Throwable e) throws JSONException { JSONObject res = new JSONObject(); res.put("message", e.getMessage()); res.put("class", e.getClass().getCanonicalName()); res.put("screen", "TODO"); res.put("stacktrace", serializeStackTrace(e.getStackTrace())); if (e.getCause() != null) { res.put("cause", serializeException(e.getCause())); }/*from w w w . ja v a2 s . com*/ return res; }
From source file:net.ymate.platform.log.AbstractLogger.java
/** * // w ww . j av a 2s.c om * * @param stackSB ??? * @param t ? * @return ?true */ protected boolean __ex(StringBuilder stackSB, Throwable t) { if (t != null) { stackSB.append("Caused by: ").append(t.getClass().getName()).append(": ") .append(StringUtils.trimToEmpty(t.getMessage())).append("\n"); StackTraceElement[] _traces = t.getStackTrace(); int _tracesSize = _traces.length; for (int _idx = 0; _idx < _tracesSize; _idx++) { if (_idx < PRINT_STACK_COUNT) { stackSB.append("\tat ") // .append(_traces[_idx]).append("\n"); } else { stackSB.append("\t... ").append(_tracesSize - PRINT_STACK_COUNT).append(" more\n"); break; } } if (__ex(stackSB, t.getCause())) { return true; } } return false; }
From source file:org.commonjava.indy.ftest.core.fixture.ThreadDumper.java
public static TestRule timeoutRule(int timeout, TimeUnit units) { return (base, description) -> new Statement() { public void evaluate() throws Throwable { System.out.printf("Setting up timeout: %d %s to wrap: %s\n", timeout, units, base); AtomicReference<Throwable> error = new AtomicReference<>(); CountDownLatch latch = new CountDownLatch(1); FutureTask<Void> task = new FutureTask<>(() -> { try { latch.countDown();/*from w w w . ja va 2s.c o m*/ base.evaluate(); } catch (Throwable t) { error.set(t); } return null; }); ThreadGroup tg = new ThreadGroup("Test Timeout Group"); Thread t = new Thread(tg, task, "Test Timeout Thread"); t.setDaemon(true); t.start(); try { System.out.println("Waiting for test to start."); latch.await(); } catch (InterruptedException e) { error.set(e); } if (error.get() == null) { try { System.out.println("Waiting for test to complete (or timeout)"); task.get(timeout, units); } catch (InterruptedException e) { error.set(e); } catch (ExecutionException e) { error.set(e.getCause()); } catch (TimeoutException e) { System.out.printf("Test timeout %d %s expired!\n", timeout, units.name()); dumpThreads(); StackTraceElement[] stackTrace = t.getStackTrace(); Exception currThreadException = new TestTimedOutException(timeout, units); if (stackTrace != null) { currThreadException.setStackTrace(stackTrace); t.interrupt(); } throw currThreadException; } } Throwable throwable = error.get(); if (throwable != null) { throw throwable; } } }; }
From source file:com.opengamma.engine.view.calcnode.MutableExecutionLog.java
public void setException(Throwable exception) { _exceptionClass = exception.getClass().getName(); _exceptionMessage = exception.getMessage(); final StringBuffer buffer = new StringBuffer(); for (StackTraceElement element : exception.getStackTrace()) { buffer.append(element.toString() + "\n"); }//from w ww .j a v a 2s . co m _exceptionStackTrace = buffer.toString(); }
From source file:at.wada811.android.library.demos.CrashExceptionHandler.java
/** * ?// ww w .ja v a2 s .co m * * @param throwable * @return * @throws JSONException */ private JSONObject getExceptionInfo(Throwable throwable) throws JSONException { JSONObject json = new JSONObject(); json.put("name", throwable.getClass().getName()); json.put("message", throwable.getMessage()); if (throwable.getStackTrace() != null) { // ExceptionStacktrace JSONArray exceptionStacktrace = new JSONArray(); for (StackTraceElement element : throwable.getStackTrace()) { exceptionStacktrace.put("at " + LogUtils.getMetaInfo(element)); } json.put("ExceptionStacktrace", exceptionStacktrace); } if (throwable.getCause() != null) { json.put("cause", throwable.getCause()); // CausedStacktrace if (throwable.getCause().getStackTrace() != null) { JSONArray causedStacktrace = new JSONArray(); for (StackTraceElement element : throwable.getCause().getStackTrace()) { causedStacktrace.put("at " + LogUtils.getMetaInfo(element)); } json.put("CausedStacktrace", causedStacktrace); } } return json; }
From source file:org.stenerud.kscrash.KSCrash.java
/** Report a Java exception. * * @param exception The exception./*from w w w . j ava 2 s .co m*/ */ public void reportJavaException(Throwable exception) { try { JSONArray array = new JSONArray(); for (StackTraceElement element : exception.getStackTrace()) { JSONObject object = new JSONObject(); object.put("file", element.getFileName()); object.put("line", element.getLineNumber()); object.put("class", element.getClassName()); object.put("method", element.getMethodName()); object.put("native", element.isNativeMethod()); array.put(object); } reportUserException(exception.getClass().getName(), exception.getMessage(), "java", exception.getStackTrace()[0].getFileName(), exception.getStackTrace()[0].getLineNumber(), array, false, false); } catch (JSONException e) { e.printStackTrace(); } }
From source file:com.jkoolcloud.tnt4j.utils.Utils.java
/** * Generates a string representation of the stack trace for an exception. * * @param ex/*from w ww. ja v a 2 s . co m*/ * exception to process * @return stack trace as a string */ public static String getStackTrace(Throwable ex) { if (ex == null) return ""; String result = ex + LINE_FEED; StackTraceElement[] trace = ex.getStackTrace(); for (int i = 0; i < trace.length; i++) result += "\tat " + trace[i] + LINE_FEED; return result; }
From source file:airbrake.Backtrace.java
private void toBacktrace(final Throwable throwable) { if (throwable == null) return;//from ww w .ja v a 2s . c om backtrace.add(causedBy(throwable)); for (final StackTraceElement element : throwable.getStackTrace()) { backtrace.add(toBacktrace(element)); } toBacktrace(throwable.getCause()); }
From source file:hjow.hgtable.util.DataUtil.java
/** * <p>, ? ?? ? ? . ?? ? ? ?? .</p> * //from w ww. j av a2s.com * @param t : , ? ? * @return ? */ public static String stackTrace(Throwable t) { StringBuffer results = new StringBuffer(""); results = results.append(t.getClass().getName() + ": " + t.getMessage() + "\n"); StackTraceElement[] traces = t.getStackTrace(); for (StackTraceElement e : traces) { results = results.append("\tat " + String.valueOf(e) + "\n"); } return results.toString(); }