List of usage examples for java.lang Throwable getStackTrace
public StackTraceElement[] getStackTrace()
From source file:org.sakaiproject.portal.util.ErrorReporter.java
/** * Format the full stack trace.//www.j av a 2 s . co m * * @param t * The throwable. * @return A display of the full stack trace for the throwable. */ protected String getStackTrace(Throwable t) { StackTraceElement[] st = t.getStackTrace(); StringBuilder buf = new StringBuilder(); if (st != null) { for (int i = 0; i < st.length; i++) { buf.append("\n at " + st[i].getClassName() + "." + st[i].getMethodName() + "(" + ((st[i].isNativeMethod()) ? "Native Method" : (st[i].getFileName() + ":" + st[i].getLineNumber())) + ")"); } buf.append("\n"); } return buf.toString(); }
From source file:grails.plugin.cache.web.filter.AbstractFilter.java
/** * This method should throw IOExceptions, not wrap them. *///w w w. jav a2 s .c o m protected void logThrowable(final Throwable throwable, final HttpServletRequest httpRequest) throws ServletException, IOException { StringBuilder messageBuffer = new StringBuilder("Throwable thrown during doFilter on request with URI: ") .append(httpRequest.getRequestURI()).append(" and Query: ").append(httpRequest.getQueryString()) .append(" : ").append(throwable.getMessage()); if (suppressStackTraces) { log.warn(messageBuffer.append("\nTop StackTraceElement: ").append(throwable.getStackTrace()[0]) .toString()); } else { log.warn(messageBuffer.toString(), throwable); } if (throwable instanceof IOException) { throw (IOException) throwable; } throw new ServletException(throwable); }
From source file:com.ihelpoo.app.AppException.java
/** * ?APP/*from w w w. j a va 2 s . c o m*/ * @param ex * @return */ private String getCrashReport(Context context, Throwable ex) { PackageInfo pinfo = ((AppContext) context.getApplicationContext()).getPackageInfo(); StringBuffer exceptionStr = new StringBuffer(); exceptionStr.append("Version: " + pinfo.versionName + "(" + pinfo.versionCode + ")\n"); exceptionStr.append("Android: " + android.os.Build.VERSION.RELEASE + "(" + android.os.Build.MODEL + ")\n"); exceptionStr.append("Exception: " + ex.getMessage() + "\n"); StackTraceElement[] elements = ex.getStackTrace(); for (int i = 0; i < elements.length; i++) { exceptionStr.append(elements[i].toString() + "\n"); } return exceptionStr.toString(); }
From source file:org.alfresco.repo.node.integrity.IntegrityChecker.java
/** * Ensures that this service is registered with the transaction and saves the event * //from w w w .j av a2 s.co m * @param event IntegrityEvent */ @SuppressWarnings("unchecked") private void save(IntegrityEvent event) { // optionally set trace if (traceOn) { // get a stack trace Throwable t = new Throwable(); t.fillInStackTrace(); StackTraceElement[] trace = t.getStackTrace(); event.addTrace(trace); // done } // register this service AlfrescoTransactionSupport.bindIntegrityChecker(this); // get the event list Map<IntegrityEvent, IntegrityEvent> events = (Map<IntegrityEvent, IntegrityEvent>) AlfrescoTransactionSupport .getResource(KEY_EVENT_SET); if (events == null) { events = new HashMap<IntegrityEvent, IntegrityEvent>(113, 0.75F); AlfrescoTransactionSupport.bindResource(KEY_EVENT_SET, events); } // check if the event is present IntegrityEvent existingEvent = events.get(event); if (existingEvent != null) { // the event (or its equivalent is already present - transfer the trace if (traceOn) { existingEvent.getTraces().addAll(event.getTraces()); } } else { // the event doesn't already exist events.put(event, event); } if (logger.isDebugEnabled()) { logger.debug("" + (existingEvent != null ? "Event already present in" : "Added event to") + " event set: \n" + " event: " + event); } }
From source file:com.android.fastlibrary.AppException.java
/** * ?APP/*w w w . j a v a 2 s .c om*/ * * @param ex * @return */ private String getCrashReport(Context context, Throwable ex) { PackageInfo pinfo = ((BaseApplication) context.getApplicationContext()).getPackageInfo(); StringBuffer exceptionStr = new StringBuffer(); exceptionStr.append("Version: " + pinfo.versionName + "(" + pinfo.versionCode + ")\n"); exceptionStr.append("Android: " + android.os.Build.VERSION.RELEASE + "(" + android.os.Build.MODEL + ")\n"); exceptionStr.append("Exception: " + ex.getMessage() + "\n"); StackTraceElement[] elements = ex.getStackTrace(); for (int i = 0; i < elements.length; i++) { exceptionStr.append(elements[i].toString() + "\n"); } return exceptionStr.toString(); }
From source file:org.obiba.opal.shell.commands.ImportCommand.java
private void printThrowable(Throwable ex, boolean withStack, int depth) { //only prints message for the top exception if (depth == 0 && !Strings.isNullOrEmpty(ex.getMessage())) getShell().printf(ex.getMessage()); StringBuilder sb = new StringBuilder(); if (depth > 0) { sb.append("Caused by: "); sb.append(ex.toString()).append("\n"); }//from w w w . jav a 2 s . c o m if (withStack) { for (StackTraceElement elem : ex.getStackTrace()) { sb.append(elem.toString()).append("\n"); } getShell().printf(sb.toString()); } Throwable cause = ex.getCause(); //we only recurse if there is a cause and not the exception itself (quite common cause of endless loops) if (cause != null && cause != ex) { printThrowable(cause, withStack, depth + 1); } }
From source file:org.commonjava.cartographer.graph.RelationshipGraph.java
public void storeProjectError(final ProjectVersionRef ref, final Throwable error) throws RelationshipGraphException { getConnectionInternal().addProjectError(ref, String.format("%s\n%s", error.getMessage(), join(error.getStackTrace(), "\n "))); for (final RelationshipGraphListener listener : listeners) { listener.projectError(this, ref, error); }/* w w w. ja va 2 s .c o m*/ }
From source file:org.nuxeo.ecm.automation.server.test.AbstractAutomationClientTest.java
@Test public void testRemoteErrorHandling() throws Exception { // assert document removed try {/* ww w . j a va 2 s.co m*/ session.newRequest(FetchDocument.ID).set("value", "/automation-test-folder/unexisting").execute(); fail("request is supposed to return 404"); } catch (RemoteException e) { Throwable remoteCause = e.getRemoteCause(); assertEquals(404, e.getStatus()); assertThat(remoteCause, is(notNullValue())); final StackTraceElement[] remoteStack = remoteCause.getStackTrace(); assertThat(remoteStack, is(notNullValue())); Boolean rollback = ((RemoteThrowable) remoteCause).getOtherNodes().get("rollback").getBooleanValue(); assertThat(rollback, is(Boolean.TRUE)); while (remoteCause.getCause() != remoteCause && remoteCause.getCause() != null) { remoteCause = remoteCause.getCause(); } String className = ((RemoteThrowable) remoteCause).getOtherNodes().get("className").getTextValue(); assertThat(className, is(DocumentNotFoundException.class.getName())); } }
From source file:com.mirth.connect.server.controllers.DefaultCodeTemplateController.java
private Throwable convertUpdateCause(Throwable t) { if (t instanceof ControllerException) { if (t.getCause() != null) { t = t.getCause();//from ww w .ja v a2 s . c om } else { StackTraceElement[] stackTrace = t.getStackTrace(); t = new Exception(t.getMessage()); t.setStackTrace(stackTrace); } } return t; }