List of usage examples for java.lang Throwable getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:com.consol.citrus.report.HtmlReporter.java
/** * Construct HTML code snippet for stack trace information. * @param cause the causing error.//from w ww . ja va2s . c o m * @return */ private String getStackTraceHtml(Throwable cause) { StringBuilder stackTraceBuilder = new StringBuilder(); stackTraceBuilder.append(cause.getClass().getName() + ": " + cause.getMessage() + "\n "); for (int i = 0; i < cause.getStackTrace().length; i++) { stackTraceBuilder.append("\n\t at "); stackTraceBuilder.append(cause.getStackTrace()[i]); } return "<tr><td colspan=\"2\">" + "<div class=\"error-detail\"><pre>" + stackTraceBuilder.toString() + "</pre>" + getCodeSnippetHtml(cause) + "</div></td></tr>"; }
From source file:org.darkware.wpman.wpcli.WPCLI.java
/** * Executes the command, ignoring any messages or data and only checking for success * or failure response codes.//from w ww.j a v a2 s.c om * * @return {@code true} if the command returned no error, {@code false} if any error * is returned. */ public boolean checkSuccess() { try { this.execute(); return true; } catch (WPCLIError e) { WPCLI.log.debug("Command returned error: {}", e.getLocalizedMessage()); return false; } catch (Throwable t) { WPCLI.log.warn("Saw unexpected exception while running a command for success/failure: {}: {}", t.getClass().getName(), t.getLocalizedMessage()); return false; } }
From source file:com.alliander.osgp.acceptancetests.deviceinstallation.FindRecentDevicesSteps.java
@DomainStep("the find recent devices request is received") public void whenTheFindRecentDevicesRequestIsReceived() { LOGGER.info("WHEN: \"the find recent devices request is received\"."); MockitoAnnotations.initMocks(this); try {//from w ww . ja v a 2 s . c o m this.response = this.deviceInstallationEndpoint.findRecentDevices(this.organisation, this.request); } catch (final Throwable t) { if (t instanceof ValidationException) { LOGGER.info("Exception: {}", ((ValidationException) t).toString()); } else { LOGGER.error("Exception: {}", t.getClass().getSimpleName()); } this.throwable = t; } }
From source file:com.bbm.common.aspect.ExceptionTransfer.java
/** * ? Exception ? ? ?? ?? ? ./*from ww w . j a va 2 s. com*/ * @param thisJoinPoint joinPoint ? * @param exception ? Exception */ public void transfer(JoinPoint thisJoinPoint, Exception exception) throws Exception { log.debug("execute ExceptionTransfer.transfer "); Class clazz = thisJoinPoint.getTarget().getClass(); Signature signature = thisJoinPoint.getSignature(); Locale locale = LocaleContextHolder.getLocale(); /** * BizException ? ?? ? ?. * Exception ?? ? ?? Exception? ? ? ?. * ? . * ? ?? Handler ? ?. */ String servicename = ""; // String errorCode = ""; // ? String errorMessage = ""; // ? String classname = ""; // ?? int servicepos = clazz.getCanonicalName().lastIndexOf("."); // .? if (servicepos > 0) { String tempStr = clazz.getCanonicalName().substring(servicepos + 1); servicepos = tempStr.lastIndexOf("Impl"); // Impl? servicename = tempStr.substring(0, servicepos); } else { servicename = clazz.getCanonicalName(); } classname = exception.getClass().getName(); //EgovBizException ? ? if (exception instanceof EgovBizException) { log.debug("Exception case :: EgovBizException "); EgovBizException be = (EgovBizException) exception; getLog(clazz).error(be.getMessage(), be.getCause()); // Exception Handler ? ?? Package Exception . (runtime ? ExceptionHandlerService ) processHandling(clazz, signature.getName(), exception, pm, exceptionHandlerServices); throw be; //RuntimeException ? ? ? DataAccessException ? ?? throw . } else if (exception instanceof RuntimeException) { log.debug("RuntimeException case :: RuntimeException "); RuntimeException be = (RuntimeException) exception; getLog(clazz).error(be.getMessage(), be.getCause()); // Exception Handler ? ?? Package Exception . processHandling(clazz, signature.getName(), exception, pm, exceptionHandlerServices); if (be instanceof DataAccessException) { /* log.debug("RuntimeException case :: DataAccessException "); DataAccessException sqlEx = (DataAccessException) be; throw sqlEx; */ log.debug("RuntimeException case :: DataAccessException "); DataAccessException dataEx = (DataAccessException) be; Throwable t = dataEx.getRootCause(); String exceptionname = t.getClass().getName(); if (exceptionname.equals("java.sql.SQLException")) { java.sql.SQLException sqlException = (java.sql.SQLException) t; errorCode = String.valueOf(sqlException.getErrorCode()); errorMessage = sqlException.getMessage(); } else if (exception instanceof org.springframework.jdbc.BadSqlGrammarException) { org.springframework.jdbc.BadSqlGrammarException sqlEx = (org.springframework.jdbc.BadSqlGrammarException) exception; errorCode = String.valueOf(sqlEx.getSQLException().getErrorCode()); errorMessage = sqlEx.getSQLException().toString(); } else if (exception instanceof org.springframework.jdbc.UncategorizedSQLException) { org.springframework.jdbc.UncategorizedSQLException sqlEx = (org.springframework.jdbc.UncategorizedSQLException) exception; errorCode = String.valueOf(sqlEx.getSQLException().getErrorCode()); errorMessage = sqlEx.getSQLException().toString(); } else if (exception instanceof org.springframework.jdbc.JdbcUpdateAffectedIncorrectNumberOfRowsException) { org.springframework.jdbc.JdbcUpdateAffectedIncorrectNumberOfRowsException sqlEx = (org.springframework.jdbc.JdbcUpdateAffectedIncorrectNumberOfRowsException) exception; errorCode = String.valueOf(sqlEx.getActualRowsAffected()); errorMessage = sqlEx.getMessage().toString(); } else if (exception instanceof org.springframework.jdbc.SQLWarningException) { org.springframework.jdbc.SQLWarningException sqlEx = (org.springframework.jdbc.SQLWarningException) exception; errorCode = String.valueOf(sqlEx.SQLWarning().getErrorCode()); errorMessage = sqlEx.getMessage().toString(); } else if (exception instanceof org.springframework.jdbc.CannotGetJdbcConnectionException) { org.springframework.jdbc.CannotGetJdbcConnectionException sqlEx = (org.springframework.jdbc.CannotGetJdbcConnectionException) exception; errorCode = String.valueOf(sqlEx.getMessage()); errorMessage = sqlEx.getMessage().toString(); } else if (exception instanceof org.springframework.jdbc.InvalidResultSetAccessException) { org.springframework.jdbc.InvalidResultSetAccessException sqlEx = (org.springframework.jdbc.InvalidResultSetAccessException) exception; errorCode = String.valueOf(sqlEx.getSQLException().getErrorCode()); errorMessage = sqlEx.getSQLException().toString(); } else { if (exception instanceof java.lang.reflect.InvocationTargetException) { java.lang.reflect.InvocationTargetException ce = (java.lang.reflect.InvocationTargetException) exception; errorCode = ""; errorMessage = ce.getTargetException().getMessage(); //strErrorMessage = getValue(ce.getTargetException().toString(), ""); } } // , ?, ?, , String[] messages = new String[] { "DataAccessException", errorCode, errorMessage, servicename, signature.getName(), classname }; throw processException(clazz, "fail.common.msg", messages, exception, locale); } // , ?, ?, , errorMessage = exception.getMessage(); String[] messages = new String[] { "RuntimeException", errorCode, errorMessage, servicename, signature.getName(), classname }; throw processException(clazz, "fail.common.msg", messages, exception, locale); //throw be; // ? ? Exception (: ) :: ? ?. } else if (exception instanceof FdlException) { log.debug("FdlException case :: FdlException "); FdlException fe = (FdlException) exception; getLog(clazz).error(fe.getMessage(), fe.getCause()); errorMessage = exception.getMessage(); // , ?, ?, , String[] messages = new String[] { "FdlException", errorCode, errorMessage, servicename, signature.getName(), classname }; throw processException(clazz, "fail.common.msg", messages, exception, locale); //throw fe; } else { //? ? Exception ? BaseException (: fail.common.msg) ?. //:: ? ?. log.debug("case :: Exception "); getLog(clazz).error(exception.getMessage(), exception.getCause()); errorMessage = exception.getMessage(); // , ?, ?, , String[] messages = new String[] { "Exception", errorCode, errorMessage, servicename, signature.getName(), classname }; throw processException(clazz, "fail.common.msg", messages, exception, locale); } }
From source file:de.tudarmstadt.lt.lm.service.UimaStringProvider.java
public List<String> getSequenceFromSentence(Sentence sentence) throws Exception { boolean handle_sentence_boundaries = Properties.handleBoundaries() == 3; // FIXME: List<String> sequence = new ArrayList<String>(); for (int i = 0; i < getLanguageModel().getOrder() - 1 && handle_sentence_boundaries; i++) sequence.add(PseudoSymbol.SEQUENCE_START.asString()); try {/*from w w w . j a v a 2 s. co m*/ List<Token> tokens = JCasUtil.selectCovered(Token.class, sentence); // Collections.sort(tokens, AnnotationBeginOffsetOrderComparator.INSTANCE); int token_count = 0; boolean filtered_last_token = false; for (Iterator<Token> iter = tokens.iterator(); iter.hasNext();) { Token token = iter.next(); if (!JCasUtil.selectCovered(FilteredItem.class, token).isEmpty()) { if (!filtered_last_token && Properties.mergeFilteredItems()) { sequence.add("<filtered>"); token_count++; filtered_last_token = true; } continue; } filtered_last_token = false; if (Properties.ignorePunctuation() && token.getPos() instanceof PUNC) continue; String word; if (Properties.ignorePunctuation() && token.getLemma() != null && token.getLemma().getValue() != null) word = token.getLemma().getValue(); else word = token.getCoveredText(); word = de.tudarmstadt.lt.utilities.StringUtils.trim_and_replace_emptyspace(word, "_"); if (Properties.useLowercase()) word = word.toLowerCase(); sequence.add(word); token_count++; } if (token_count < getLanguageModel().getOrder()) return Collections.emptyList(); } catch (Throwable t) { while (t != null) { LOG.error(String.format("Error while processing sentence. %s:%s", t.getClass().getName(), t.getMessage()), t); t = t.getCause(); } } // sequence.add(PseudoSymbol.SEQUENCE_END.asString()); return sequence; }
From source file:com.solace.samples.cloudfoundry.securesession.controller.SolaceController.java
/** * This formats a string showing the exception class name and message, as * well as the class name and message of the underlying cause if it exists. * Then it returns that string in a ResponseEntity. * //from ww w . j av a2 s . com * @param exception * @return ResponseEntity<String> */ private ResponseEntity<String> handleError(Exception exception) { Throwable cause = exception.getCause(); String causeString = ""; if (cause != null) { causeString = "Cause: " + cause.getClass() + ": " + cause.getMessage(); } String desc = String.format("{'description': ' %s: %s %s'}", exception.getClass().toString(), exception.getMessage(), causeString); return new ResponseEntity<>(desc, HttpStatus.BAD_REQUEST); }
From source file:de.metas.ui.web.config.WebuiExceptionHandler.java
private void addErrorDetails(final Map<String, Object> errorAttributes, final RequestAttributes requestAttributes, final boolean includeStackTrace) { Throwable error = getError(requestAttributes); if (error != null) { while (error instanceof ServletException && error.getCause() != null) { error = ((ServletException) error).getCause(); }// w w w . j a va 2 s. c o m errorAttributes.put(ATTR_Exception, error.getClass().getName()); addErrorMessage(errorAttributes, error); if (includeStackTrace && !isExcludeFromLogging(error)) { addStackTrace(errorAttributes, error); } } final Object message = getAttribute(requestAttributes, RequestDispatcher.ERROR_MESSAGE); if ((!StringUtils.isEmpty(message) || errorAttributes.get(ATTR_Message) == null) && !(error instanceof BindingResult)) { errorAttributes.put(ATTR_Message, StringUtils.isEmpty(message) ? "No message available" : message); } }
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 a v a 2 s.c o m 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:at.ac.tuwien.dsg.comot.m.common.event.state.ExceptionMessage.java
public ExceptionMessage(String serviceId, String origin, Long time, String eventCauseId, Exception exception) { super();// www. j av a 2 s. co m Throwable root = ExceptionUtils.getRootCause(exception); String type; String message; String details; if (root == null) { type = exception.getClass().getName(); message = exception.getMessage(); details = ExceptionUtils.getStackTrace(exception); } else { type = root.getClass().getName(); message = root.getMessage(); details = ExceptionUtils.getStackTrace(root); } this.origin = origin; this.type = type; this.message = message; this.details = details; this.serviceId = serviceId; this.time = time; this.eventCauseId = eventCauseId; }
From source file:jp.co.acroquest.endosnipe.common.logger.ENdoSnipeLogger.java
/** * ???<br />/*www . j av a 2s. co m*/ * * @param throwable {@link Throwable} * @deprecated ????????????? * ?? {@link #log(String, Throwable, Object...)} ??????? */ @Deprecated public void log(final Throwable throwable) { error(throwable.getClass().getName() + " : " + throwable.getMessage(), throwable); }