List of usage examples for java.lang Throwable getStackTrace
public StackTraceElement[] getStackTrace()
From source file:org.jspare.server.jetty.JettyResponse.java
@Override public void systemError(Throwable t) { this.entity = t.getStackTrace(); systemError(); }
From source file:org.trianacode.taskgraph.util.FileUtils.java
public static String formatThrowable(Throwable t) { StringBuilder sb = new StringBuilder(t.getClass().getName()); t.fillInStackTrace();// w ww . j a v a 2 s .co m StackTraceElement[] trace = t.getStackTrace(); for (StackTraceElement stackTraceElement : trace) { sb.append("\t\n").append(stackTraceElement); } Throwable cause = t.getCause(); if (cause != null) { sb.append(formatThrowable(cause)); } return sb.toString(); }
From source file:org.mule.config.dsl.DSLException.java
public String getSummaryMessage() { final MuleException e = ExceptionHelper.getRootMuleException(this); if (!e.equals(this)) { return getMessage(); }//from w w w.jav a 2 s . co m final StringBuffer buf = new StringBuffer(1024); buf.append(org.apache.commons.lang.SystemUtils.LINE_SEPARATOR).append(StringUtils.repeat('*', 80)) .append(org.apache.commons.lang.SystemUtils.LINE_SEPARATOR); buf.append("Message : ").append(message) .append(org.apache.commons.lang.SystemUtils.LINE_SEPARATOR); buf.append("Code : ").append("MULE_ERROR-").append(getExceptionCode() + getMessageCode()) .append(org.apache.commons.lang.SystemUtils.LINE_SEPARATOR); // print exception stack buf.append(StringUtils.repeat('-', 80)).append(org.apache.commons.lang.SystemUtils.LINE_SEPARATOR); buf.append(CoreMessages.exceptionStackIs()).append(org.apache.commons.lang.SystemUtils.LINE_SEPARATOR); buf.append(org.apache.commons.lang.StringUtils.abbreviate(ExceptionHelper.getExceptionStack(this), 5000)); buf.append(StringUtils.repeat('-', 80)).append(org.apache.commons.lang.SystemUtils.LINE_SEPARATOR); buf.append(CoreMessages.rootStackTrace()).append(org.apache.commons.lang.SystemUtils.LINE_SEPARATOR); final Throwable root = ExceptionHelper.getRootException(this); final Throwable rootSummary = ExceptionHelper.summarise(root, 3); final StringWriter w = new StringWriter(); final PrintWriter p = new PrintWriter(w); rootSummary.printStackTrace(p); buf.append(org.apache.commons.lang.StringUtils.abbreviate(w.toString(), 5000)); buf.append(" + " + root.getStackTrace().length + " more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)") .append(org.apache.commons.lang.SystemUtils.LINE_SEPARATOR); buf.append(StringUtils.repeat('*', 80)).append(org.apache.commons.lang.SystemUtils.LINE_SEPARATOR); return buf.toString(); }
From source file:org.carewebframework.ui.ExceptionController.java
/** * Appends the stack trace for the specified exception to the display. * /* w ww . j a v a2 s. c om*/ * @param err Exception whose stack trace will be appended. */ private void appendStackTrace(final Throwable err) { if (err != null) { final Class<?> clazz = err.getClass(); final String msg = err.getMessage(); //final Throwable cause = err.getCause();//should be null this.txtStackTrace.setValue(StringUtils.defaultString(this.txtStackTrace.getValue()) + StringUtils.trimToEmpty(clazz.getCanonicalName()) + ": " + StringUtils.trimToEmpty(msg) + "\n"); for (final StackTraceElement element : err.getStackTrace()) { this.txtStackTrace.setValue( StringUtils.defaultString(this.txtStackTrace.getValue()) + String.valueOf(element) + "\n"); } } }
From source file:org.j2free.error.HoptoadNotifier.java
private Element createBacktraceNode(Document doc, Throwable thrown, StackTraceElement lastFrame) { Element node = doc.createElement("backtrace"), e; if (thrown != null) { for (StackTraceElement frame : thrown.getStackTrace()) { e = doc.createElement("line"); e.setAttribute("file", frame.getFileName()); e.setAttribute("number", String.valueOf(frame.getLineNumber())); e.setAttribute("method", frame.getMethodName()); node.appendChild(e);/* w ww. ja v a 2 s . c o m*/ } Throwable rootCause = unwindException(thrown); if (rootCause != null && rootCause != thrown) { // DIVIDER --- e = doc.createElement("line"); e.setAttribute("file", "--------------------"); e.setAttribute("number", "0"); e.setAttribute("method", "--------------------"); node.appendChild(e); for (StackTraceElement frame : rootCause.getStackTrace()) { e = doc.createElement("line"); e.setAttribute("file", frame.getFileName()); e.setAttribute("number", String.valueOf(frame.getLineNumber())); e.setAttribute("method", frame.getMethodName()); node.appendChild(e); } } } else if (lastFrame != null) { e = doc.createElement("line"); e.setAttribute("file", lastFrame.getFileName()); e.setAttribute("number", String.valueOf(lastFrame.getLineNumber())); e.setAttribute("method", lastFrame.getMethodName()); node.appendChild(e); } else { e = doc.createElement("line"); e.setAttribute("file", "unknown"); e.setAttribute("number", "0"); e.setAttribute("method", "unknown"); node.appendChild(e); } return node; }
From source file:com.alliander.osgp.acceptancetests.configurationmanagement.SetConfigurationDataSteps.java
@DomainStep("the set configuration data request is received") public void whenRequestIsReceived() { LOGGER.info("WHEN: the set configuration data request is received"); try {/*from www. j a v a 2 s. co m*/ this.setConfigurationAsyncResponse = this.configurationManagementEndpoint .setConfiguration(ORGANISATION_ID, this.request); } catch (final Throwable t) { LOGGER.error("Exception [{}]: {}", t.getClass().getSimpleName(), t.getStackTrace()); this.throwable = t; } }
From source file:org.dspace.storage.rdbms.MockDatabaseManager.java
/** * Obtain an RDBMS connection.// www .j a va 2 s . c om * * @return A new database connection. * @exception SQLException * If a database error occurs, or a connection cannot be * obtained. */ @Mock public static Connection getConnection() throws SQLException { initialize(); //we need to find who creates so many connections Throwable t = new Throwable(); StackTraceElement[] elements = t.getStackTrace(); String callers = ""; for (int i = 0; i < Math.min(elements.length, 4); i++) { callers += " > " + elements[i].getClassName() + ":" + elements[i].getMethodName(); } //uncomment to see the infromation on callers //log.info(callers+" ("+connectionPool.getNumActive()+" "+connectionPool.getNumIdle()+")"); return DriverManager.getConnection("jdbc:apache:commons:dbcp:" + poolName); }
From source file:org.dspace.storage.rdbms.MockDatabaseManager.java
/** * Release resources associated with this connection. * * @param c/* w w w . j a va2 s. com*/ * The connection to release */ @Mock public static void freeConnection(Connection c) { //we check who frees the connection Throwable t = new Throwable(); StackTraceElement[] elements = t.getStackTrace(); String callers = ""; for (int i = 0; i < Math.min(elements.length, 4); i++) { callers += " > " + elements[i].getClassName() + ":" + elements[i].getMethodName(); } //uncomment to see the infromation on callers //log.info(callers+" ("+connectionPool.getNumActive()+" "+connectionPool.getNumIdle()+")"); try { if (c != null) { c.close(); } } catch (SQLException e) { log.warn(e.getMessage()); } }
From source file:org.rapla.rest.gwtjsonrpc.server.JsonServlet.java
public static JsonObject getError(String version, int code, Throwable failure, GsonBuilder gb) { final JsonObject error = new JsonObject(); String message = failure.getMessage(); if (message == null) { message = failure.toString();//from w w w . j av a2 s. c om } Gson gson = gb.create(); if ("jsonrpc".equals(version)) { error.addProperty("code", code); error.addProperty("message", message); JsonObject errorData = new JsonObject(); errorData.addProperty("exception", failure.getClass().getName()); // FIXME Replace with generic solution for exception param // serialization if (failure instanceof DependencyException) { JsonArray params = new JsonArray(); for (String dep : ((DependencyException) failure).getDependencies()) { params.add(new JsonPrimitive(dep)); } errorData.add("params", params); } JsonArray stackTrace = new JsonArray(); for (StackTraceElement el : failure.getStackTrace()) { JsonElement jsonRep = gson.toJsonTree(el); stackTrace.add(jsonRep); } errorData.add("stacktrace", stackTrace); error.add("data", errorData); } else { error.addProperty("name", "JSONRPCError"); error.addProperty("code", 999); error.addProperty("message", message); } return error; }
From source file:org.sakaiproject.portal.util.ErrorReporter.java
/** * Format a one-level stack trace, just showing the place where the * exception occurred (the first entry in the stack trace). * // ww w. j av a 2s .c o m * @param t * The throwable. * @return A display of the first stack trace entry for the throwable. */ protected String getOneTrace(Throwable t) { StackTraceElement[] st = t.getStackTrace(); StringBuilder buf = new StringBuilder(); if (st != null && st.length > 0) { buf.append("\n at " + st[1].getClassName() + "." + st[1].getMethodName() + "(" + ((st[1].isNativeMethod()) ? "Native Method" : (st[1].getFileName() + ":" + st[1].getLineNumber())) + ")\n"); } return buf.toString(); }