List of usage examples for java.lang Throwable getStackTrace
public StackTraceElement[] getStackTrace()
From source file:org.lilyproject.avro.AvroConverter.java
private static AvroExceptionCause convertCause(Throwable throwable) { AvroExceptionCause cause = new AvroExceptionCause(); cause.setClassName(throwable.getClass().getName()); cause.setMessage(throwable.getMessage()); StackTraceElement[] stackTrace = throwable.getStackTrace(); cause.setStackTrace(new ArrayList<AvroStackTraceElement>(stackTrace.length)); for (StackTraceElement el : stackTrace) { cause.getStackTrace().add(convert(el)); }/* ww w.j a v a2 s .c o m*/ return cause; }
From source file:org.smartfrog.test.SmartFrogTestManager.java
/** * extract as much info as we can from a throwable. * * @param thrown what was thrown// w w w. j ava 2 s .c o m * * @return a string describing the throwable; includes a stack trace */ public static String extractDiagnosticsInfo(Throwable thrown) { StringBuilder buffer = new StringBuilder(); thrown.getStackTrace(); buffer.append("Message: "); buffer.append(thrown.toString()); buffer.append('\n'); buffer.append("Class: "); buffer.append(thrown.getClass().getName()); buffer.append('\n'); buffer.append("Stack: "); StackTraceElement[] stackTrace = thrown.getStackTrace(); for (StackTraceElement frame : stackTrace) { buffer.append(frame.toString()); buffer.append('\n'); } return buffer.toString(); }
From source file:org.red5.server.net.remoting.FlexMessagingService.java
/** * Construct error message from exception. * //from w ww .ja v a2 s. c om * @param request request * @param faultCode fault code * @param faultString fautl string * @param error error * @return message */ public static ErrorMessage returnError(AbstractMessage request, String faultCode, String faultString, Throwable error) { ErrorMessage result = returnError(request, faultCode, faultString, ""); if (error instanceof ClientDetailsException) { result.extendedData = ((ClientDetailsException) error).getParameters(); if (((ClientDetailsException) error).includeStacktrace()) { StringBuilder stack = new StringBuilder(); for (StackTraceElement element : error.getStackTrace()) { stack.append(element.toString()).append('\n'); } result.faultDetail = stack.toString(); } } result.rootCause = error; return result; }
From source file:cat.ereza.customactivityoncrash.CustomActivityOnCrash.java
/** * INTERNAL method that checks if the stack trace that just crashed is conflictive. This is true in the following scenarios: * - The application has crashed while initializing (handleBindApplication is in the stack) * - The error activity has crashed (activityClass is in the stack) * * @param throwable The throwable from which the stack trace will be checked * @param activityClass The activity class to launch when the app crashes * @return true if this stack trace is conflictive and the activity must not be launched, false otherwise *///from w w w . java 2 s . c o m private static boolean isStackTraceLikelyConflictive(Throwable throwable, Class<? extends Activity> activityClass) { do { StackTraceElement[] stackTrace = throwable.getStackTrace(); for (StackTraceElement element : stackTrace) { if ((element.getClassName().equals("android.app.ActivityThread") && element.getMethodName().equals("handleBindApplication")) || element.getClassName().equals(activityClass.getName())) { return true; } } } while ((throwable = throwable.getCause()) != null); return false; }
From source file:com.oncore.calorders.core.utils.FormatHelper.java
/** * This method returns the stack trace of an exception * * @param throwable The exception/* ww w .j a va2 s. c o m*/ * @return The stack trace in string */ public static String getStackTrace(Throwable throwable) { StringBuilder trace = new StringBuilder(); trace.append(throwable.getClass().getCanonicalName()); trace.append("\n\t"); trace.append(throwable.getMessage()); trace.append("\n"); for (StackTraceElement stackTrace : throwable.getStackTrace()) { trace.append(stackTrace.toString()); trace.append("\n\t"); } return trace.toString(); }
From source file:com.tussle.main.Utility.java
public static JsonValue exceptionToJson(Throwable ex) { JsonValue topValue = new JsonValue(JsonValue.ValueType.object); JsonValue exceptionClass = new JsonValue(ex.getClass().toString()); topValue.addChild("Exception Class", exceptionClass); if (ex.getLocalizedMessage() != null) { JsonValue exceptionMessage = new JsonValue(ex.getLocalizedMessage()); topValue.addChild("Exception Message", exceptionMessage); }/* ww w .j ava 2 s . c o m*/ if (ex.getCause() != null) { JsonValue exceptionCause = new JsonValue(ex.getCause().toString()); topValue.addChild("Exception Cause", exceptionCause); } JsonValue stackTrace = new JsonValue(JsonValue.ValueType.array); for (StackTraceElement element : ex.getStackTrace()) stackTrace.addChild(new JsonValue(element.toString())); topValue.addChild("Stack Trace", stackTrace); return topValue; }
From source file:org.topazproject.otm.impl.SessionImpl.java
private static Throwable trimStackTrace(Throwable t, int offset, int levels) { StackTraceElement[] trace = t.getStackTrace(); if (trace.length > offset) { if ((trace.length - offset) < levels) levels = trace.length - offset; StackTraceElement[] copy = new StackTraceElement[levels]; System.arraycopy(trace, offset, copy, 0, levels); t.setStackTrace(copy);//from w ww.ja va2s . c o m } return t; }
From source file:org.nuessler.junit.util.rule.FailureLogger.java
@Override protected void failed(Throwable failure, Description description) { List<Throwable> failures = (failure instanceof MultipleFailureException) ? ((MultipleFailureException) failure).getFailures() : Collections.singletonList(failure); for (Throwable t : failures) { StackTraceElement testClassElement = findStrackTraceForClass(t.getStackTrace(), description.getClassName()); if (testClassElement != null) { log(formatMessage(description, testClassElement, t)); }/*from ww w .ja va2 s . c o m*/ } }
From source file:io.hightide.handlers.ErrorHandler.java
private String printException(Throwable t) { StackTraceElement ste = t.getStackTrace().length > 0 ? t.getStackTrace()[0] : null; String message;//from w w w .j av a2 s . c om if (nonNull(t.getMessage())) { message = htmlify(t.getMessage()); } else { message = ""; } StringBuilder sb = new StringBuilder(); sb.append("<div><strong>Error Message:</strong> ").append(t.getClass().getName()).append(" - ") .append(message).append("<br/><br/>"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); t.printStackTrace(new PrintStream(baos)); sb.append("<strong>Stacktrace</strong><br/><div class='exception'>").append(htmlify(baos.toString())) .append("</div>"); //sb.append("File name: ").append(ste.getFileName()).append(" at line ").append(ste.getLineNumber()).append(nl); //sb.append("Method Called: ").append(ste.getClassName()).append(".").append(ste.getMethodName()); return sb.toString(); }
From source file:com.cloud.utils.log.CglibThrowableRenderer.java
/** * This method adds the stack traces retrieved from {@link Throwable#getStackTrace()} * The maxNumberOfStack attribute indicates the number of stacks that will be added, * if that value is 0, then all of the stack traces will be added, otherwise the stack traces will be limited to that number * @param th//from w w w. ja va2 s . c o m * @param lines * @param maxNumberOfStack */ private void addStackTraceToList(Throwable th, List<String> lines, int maxNumberOfStack) { StackTraceElement[] elements = th.getStackTrace(); if (maxNumberOfStack == 0 || maxNumberOfStack > elements.length) { maxNumberOfStack = elements.length; } for (int i = 0; i < maxNumberOfStack; i++) { StackTraceElement element = elements[i]; if (StringUtils.contains(element.getClassName(), "net.sf.cglib.proxy")) { continue; } lines.add("\tat " + element.toString()); } if (maxNumberOfStack < elements.length) { lines.add("\t... " + (elements.length - maxNumberOfStack) + " more"); } }