List of usage examples for java.lang Throwable getStackTrace
public StackTraceElement[] getStackTrace()
From source file:com.fanniemae.ezpie.LogManager.java
public void addErrorMessage(Throwable ex, Boolean isInner) { String logGroup = isInner ? "" : "** ERROR **"; String inner = isInner ? "Inner " : ""; if (ex == null) { updateLog(true, "", inner + "Exception Type", "null - no details available."); return;/*from w w w . j av a 2 s . c o m*/ } String message = ex.getMessage(); if (StringUtilities.isNullOrEmpty(message)) { message = "See stack trace for error details."; } updateLog(true, logGroup, inner + "Message", message); String exceptionName = ex.getClass().getName(); if (!"java.lang.RuntimeException".equals(exceptionName) && !exceptionName.contains("PieException")) { updateLog(true, "", inner + "Exception Type", exceptionName); } StringBuilder sbStack = new StringBuilder(); boolean addLinebreak = false; for (StackTraceElement ele : ex.getStackTrace()) { if (addLinebreak) { sbStack.append(getNewLineTab()); } sbStack.append(ele.toString()); addLinebreak = true; } updateLog(true, "", inner + "Details", sbStack.toString()); Throwable innerException = ex.getCause(); if (innerException != null) { addErrorMessage(innerException, true); } }
From source file:com.fengduo.spark.commons.component.ComponentController.java
@ExceptionHandler(Throwable.class) public ModelAndView handleIOException(Throwable e) throws Throwable { if (AnnotationUtils.findAnnotation(e.getClass(), ResponseStatus.class) != null) { throw e;//from w ww.j a v a 2s . c o m } if (request == null && response == null) { throw e; } if (request == null && response != null) { response.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=UTF-8"); OutputStream out = response.getOutputStream(); PrintWriter pw = new PrintWriter(new OutputStreamWriter(out, "utf-8")); pw.println("{\"code\":1,\"msg\":\",?!\",\"data\":\"\"}"); pw.flush(); pw.close(); } ModelAndView mav = new ModelAndView(); // if (InvokeTypeTools.isAjax(request)) { // return createJsonMav("server exceptin or error", ResultCode.ERROR, e.getMessage()); // } mav.addObject("exception", e.getCause() == null ? StringUtils.EMPTY : e.getCause().toString()); mav.addObject("msg", StringUtils.isEmpty(e.getMessage()) ? e.toString() : e.getMessage()); mav.addObject("stackTrace", e.getStackTrace().toString()); if (request.getRequestURI() != null) { mav.addObject("url", request.getRequestURI().toString()); } mav.setViewName("error"); return mav; }
From source file:com.zb.app.common.component.ComponentController.java
@ExceptionHandler(Throwable.class) public ModelAndView handleIOException(Throwable e) throws Throwable { if (AnnotationUtils.findAnnotation(e.getClass(), ResponseStatus.class) != null) { throw e;/* ww w . j a va 2 s . co m*/ } if (request == null && response == null) { throw e; } if (request == null && response != null) { response.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=UTF-8"); OutputStream out = response.getOutputStream(); PrintWriter pw = new PrintWriter(new OutputStreamWriter(out, "utf-8")); pw.println("{\"code\":1,\"msg\":\",?!\",\"data\":\"\"}"); pw.flush(); pw.close(); } ModelAndView mav = new ModelAndView(); if (InvokeTypeTools.isAjax(request)) { return createJsonMav("server exceptin or error", ResultCode.ERROR, e.getMessage()); } mav.addObject("exception", e.getCause() == null ? StringUtils.EMPTY : e.getCause().toString()); mav.addObject("msg", StringUtils.isEmpty(e.getMessage()) ? e.toString() : e.getMessage()); mav.addObject("stackTrace", e.getStackTrace().toString()); if (request.getRequestURI() != null) { mav.addObject("url", request.getRequestURI().toString()); } mav.setViewName("error"); return mav; }
From source file:com.fengduo.bee.commons.component.ComponentController.java
@ExceptionHandler(Throwable.class) public ModelAndView handleIOException(Throwable e) throws Throwable { if (AnnotationUtils.findAnnotation(e.getClass(), ResponseStatus.class) != null) { throw e;/* ww w . j a va2 s . c om*/ } if (request == null && response == null) { throw e; } if (request == null && response != null) { response.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=UTF-8"); OutputStream out = response.getOutputStream(); PrintWriter pw = new PrintWriter(new OutputStreamWriter(out, "utf-8")); pw.println("{\"code\":1,\"msg\":\",?!\",\"data\":\"\"}"); pw.flush(); pw.close(); } ModelAndView mav = new ModelAndView(); // if (InvokeTypeTools.isAjax(request)) { // return createJsonMav("server exceptin or error", ResultCode.ERROR, // e.getMessage()); // } mav.addObject("exception", e.getCause() == null ? StringUtils.EMPTY : e.getCause().toString()); mav.addObject("msg", StringUtils.isEmpty(e.getMessage()) ? e.toString() : e.getMessage()); mav.addObject("stackTrace", e.getStackTrace().toString()); if (request.getRequestURI() != null) { mav.addObject("url", request.getRequestURI().toString()); } mav.setViewName("error"); return mav; }
From source file:phex.download.swarming.SWDownloadCandidate.java
public void addToCandidateLog(Throwable th) { if (candidateLogBuffer != null) { StackTraceElement[] stackTrace = th.getStackTrace(); if (stackTrace == null) { return; }/* w w w. j av a2 s . c om*/ for (int i = 0; i < 2 && i < stackTrace.length; i++) { LogRecord record = new LogRecord(this, stackTrace[i].toString()); candidateLogBuffer.addLogRecord(record); } } }
From source file:net.ymate.platform.log.slf4j.Log4jLogger.java
protected void __doBuildEx(Object info, Throwable e, ILogger.LogLevel level, Marker marker) { StringBuilder _exSB = new StringBuilder( DateTimeUtils.formatTime(System.currentTimeMillis(), DateTimeUtils.YYYY_MM_DD_HH_MM_SS_SSS)) .append(level.getDispName()).append('[').append(Thread.currentThread().getId()).append(':') .append(__doMakeCallerInfo()).append(']').append(' ') .append(info == null ? StringUtils.EMPTY : StringUtils.trimToEmpty(info.toString())); if (e != null) { StringBuilder _stackSB = new StringBuilder(e.getClass().getName()).append(": ") .append(StringUtils.EMPTY).append(StringUtils.trimToEmpty(e.getMessage())).append("\n"); StackTraceElement[] _stacks = e.getStackTrace(); for (StackTraceElement _stack : _stacks) { _stackSB.append("\tat ").append(_stack).append("\n"); }/*w w w . jav a 2 s . c o m*/ __ex(_stackSB, e.getCause()); _exSB.append("- ").append(_stackSB); } __logger.log(Level.toLevel(level.getName(), Level.ALL), getMarker(marker), _exSB.toString()); // if (__allowOutputConsole) { System.out.println(_exSB.toString()); } }
From source file:org.apache.ddlutils.task.DumpMetadataTask.java
/** * Dumps the property represented by the given method in the current element in the given writer. * /* w w w .j a v a2 s. c o m*/ * @param xmlWriter The XML writer to write to * @param obj The instance we're working on * @param propGetter The method for accessing the property */ private void dumpProperty(PrettyPrintingXmlWriter xmlWriter, Object obj, Method propGetter) { try { addProperty(xmlWriter, getPropertyName(propGetter.getName()), propGetter.invoke(obj, null)); } catch (Throwable ex) { log("Could not dump property " + propGetter.getName() + ": " + ex.getStackTrace(), Project.MSG_ERR); } }
From source file:org.vulpe.controller.struts.interceptor.VulpeExceptionMappingInterceptor.java
/** * * @param invocation/*from w w w .j ava 2 s . c om*/ * @param exception * @return */ protected String treatExceptionMessage(final ActionInvocation invocation, final Throwable exception) { final VulpeStrutsController<?, ?> action = (VulpeStrutsController<?, ?>) invocation.getAction(); final Throwable cause = getCause(exception); String message = cause.getMessage(); String key = exception.getClass().getName(); if (cause instanceof JspException) { key = cause.getClass().getName(); } else if (cause instanceof SQLException) { key = cause.getClass().getName(); } message = action.vulpe.controller().text(key); final String contactAdministratorMessageKey = "vulpe.error.contact.system.administrator"; message += action.vulpe.controller().text(contactAdministratorMessageKey); if (isDebug(action)) { final String errorOccurrenceDebugKey = "vulpe.error.occurrence.debug"; message += action.vulpe.controller().text(errorOccurrenceDebugKey); if (exception instanceof NullPointerException) { final StackTraceElement ste = exception.getStackTrace()[0]; final String fileName = ste.getFileName().replace(".java", ""); final String methodName = ste.getMethodName(); final int lineNumber = ste.getLineNumber(); message += action.vulpe.controller().text(key + ".debug", fileName, methodName, lineNumber); } else { message += "<i>" + (exception instanceof VulpeValidationException ? "entity" : cause.getMessage()) + "</i>"; } } return message; }
From source file:com.konakart.actions.BaseAction.java
/** * Returns a string containing the stack trace of the exception and its cause * /*from w w w . j a v a 2 s. c o m*/ * @param e * @return Returns a string containing the stack trace */ private String getExceptionMessage(Exception e, boolean full) { StringBuffer sb = new StringBuffer(); // Get the stack trace of the exception sb.append("<br>Exception Name = "); sb.append(e.getClass().getName()); sb.append("<br>Exception Message = "); String msg = e.getMessage(); if (msg == null || msg.equalsIgnoreCase("null")) { msg = "No further details available"; } else { msg = StringEscapeUtils.escapeHtml(msg); } sb.append(msg); if (log.isDebugEnabled() || full) { sb.append("<br>Exception Stack Trace = "); StackTraceElement[] ste = e.getStackTrace(); for (int i = 0; i < ste.length; i++) { sb.append("<br> at "); sb.append(ste[i].toString()); } // Get the stack trace of the exception cause Throwable eCause = e.getCause(); if (eCause != null) { sb.append("<br><br>Exception Cause = "); sb.append(eCause.getClass().getName()); StackTraceElement[] ste1 = eCause.getStackTrace(); for (int i = 0; i < ste1.length; i++) { sb.append("<br> at "); sb.append(ste1[i].toString()); } } } return sb.toString(); }
From source file:org.appverse.web.framework.backend.core.enterprise.aop.managers.impl.live.ExceptionManagerImpl.java
@Override public void logAndRethrowException(final Method method, final Object[] args, final Object target, final Throwable ex) throws Throwable { if (target instanceof AbstractIntegrationService || target instanceof Repository) { logger.error("Integration Exception Executing Service: " + target.getClass().getSimpleName() + " Method: " + method.getName(), ex); if (!(ex instanceof IntegrationException)) { throw new IntegrationException(ex); } else {/*from w ww .j a va 2 s. co m*/ throw ex; } } else if (target instanceof AbstractBusinessService) { if (!(ex instanceof IntegrationException)) { logger.error("Business Exception Executing Service: " + target.getClass().getSimpleName() + " Method: " + method.getName(), ex); } if (ex instanceof IntegrationException) { IntegrationException iex = (IntegrationException) ex; BusinessException bex = new BusinessException(ex); bex.setStackTrace(iex.getStackTrace()); throw bex; } else if (ex instanceof BusinessException) { throw ex; } else { BusinessException bex = new BusinessException(ex); bex.setStackTrace(ex.getStackTrace()); } } else if (target instanceof AbstractPresentationService) { if (!(ex instanceof BusinessException)) { logger.error("Presentation Exception Executing Service: " + target.getClass().getSimpleName() + " Method: " + method.getName(), ex); } if (ex instanceof BusinessException) { BusinessException bex = (BusinessException) ex; PresentationException pex = new PresentationException(ex); pex.setStackTrace(bex.getStackTrace()); throw pex; } else if (ex instanceof PresentationException) { throw ex; } else { throw new PresentationException(ex.getMessage(), ex); } } }