List of usage examples for java.lang Throwable getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:com.dianping.avatar.cache.util.CacheMonitorUtil.java
/** * ?hawk//from w w w. j a v a 2s .c o m * @param errorMsg * @param throwable */ public static void logCacheError(String errorMsg, Throwable throwable) { try { String factorName = StringUtils.substringBefore(errorMsg, "["); int logFactorNew = getNewLogFactor(factorName); if (logFactorNew % 100 == 0) { logger.error("Operate cache error: " + errorMsg, throwable); } if (hawkClass != null) { if (logFactorNew % 300 == 0) { Hawk.log(KEY_CACHE, "cache-operate-error", null, null, throwable.getClass().getName(), errorMsg, getErrorString(throwable)); } } } catch (Throwable t) { if (logFactor3++ % 300 == 0) { logger.error("Log cache-error failed.", throwable); } } }
From source file:io.appium.java_client.events.DefaultAspect.java
private static Throwable getRootCause(Throwable thrown) { Class<? extends Throwable> throwableClass = thrown.getClass(); if (!InvocationTargetException.class.equals(throwableClass) && !RuntimeException.class.equals(throwableClass)) { return thrown; }//from w ww.j av a 2 s.c om if (thrown.getCause() != null) { return getRootCause(thrown.getCause()); } return thrown; }
From source file:com.evolveum.midpoint.report.impl.ReportUtils.java
public static String prettyPrintForReport(Object value) { if (value == null) { return ""; }//from www . j a va 2s .c o m if (value instanceof MetadataType) { return ""; } //special handling for byte[], some problems with jasper when printing if (byte[].class.equals(value.getClass())) { return prettyPrintForReport((byte[]) value); } // 1. Try to find prettyPrintForReport in this class first if (value instanceof Containerable) { //e.g. RoleType needs to be converted to PCV in order to format properly value = (((Containerable) value).asPrismContainerValue()); } for (Method method : ReportUtils.class.getMethods()) { if (method.getName().equals("prettyPrintForReport")) { Class<?>[] parameterTypes = method.getParameterTypes(); if (parameterTypes.length == 1 && parameterTypes[0].equals(value.getClass())) { try { return (String) method.invoke(null, value); } catch (Throwable e) { return "###INTERNAL#ERROR### " + e.getClass().getName() + ": " + e.getMessage() + "; prettyPrintForReport method for value " + value; } } } } // 2. Default to PrettyPrinter.prettyPrint String str = PrettyPrinter.prettyPrint(value); if (str.length() > 1000) { return str.substring(0, 1000); } return str; }
From source file:hudson.UtilTest.java
/** Returns all classes in the exception hierarchy. */ private static Iterable<Class<?>> calcExceptionHierarchy(Throwable t) { final List<Class<?>> result = Lists.newArrayList(); for (; t != null; t = t.getCause()) result.add(t.getClass()); return result; }
From source file:de.tudarmstadt.lt.ltbot.postprocessor.DecesiveValueProducerPerplexity.java
static void addExtraInfo(CrawlURI uri, String key, Object value) { try {/* www. j a va2s. c om*/ uri.getExtraInfo().put(key, value); uri.getData().put(key, value); } catch (Throwable t) { for (int i = 1; t != null && i < 10; i++) { LOG.log(Level.WARNING, String.format("Failed to add perplexity value to extra info for uri: '%s' (%d-%s:%s).", uri.toString(), i, t.getClass().getName(), t.getMessage())); t = t.getCause(); } } }
From source file:com.xqdev.sql.MLSQL.java
private static void addExceptions(Element meta, Throwable t) { if (t == null) return;//from w w w . ja v a2 s . c o m Namespace sql = meta.getNamespace(); Element exceptions = new Element("exceptions", sql); meta.addContent(exceptions); do { exceptions.addContent(new Element("exception", sql).setAttribute("type", t.getClass().getName()) .addContent(new Element("reason", sql).setText(t.getMessage()))); Log.log(t); t = t.getCause(); } while (t != null); }
From source file:com.wavemaker.runtime.data.util.DataServiceUtils.java
public static RuntimeException unwrap(Throwable th) { th = SystemUtils.getRootException(th); if (InvalidDataAccessResourceUsageException.class.isAssignableFrom(th.getClass())) { InvalidDataAccessResourceUsageException e = (InvalidDataAccessResourceUsageException) th; if (e.getRootCause() != null) { th = e.getRootCause();/* w w w. j a va 2 s .co m*/ } } if (SQLGrammarException.class.isAssignableFrom(th.getClass())) { SQLGrammarException s = (SQLGrammarException) th; if (s.getSQLException() != null) { th = s.getSQLException(); } else if (s.getCause() != null) { th = s.getCause(); } } if (th instanceof RuntimeException) { return (RuntimeException) th; } else { return new DataServiceRuntimeException(th); } }
From source file:org.artifactory.util.HttpClientUtils.java
/** * @param e The throwable to inspect for the error message * @return Most fitting error message for the given throwable. Tries to prevent empty exception messages. *//* w w w. jav a 2 s.co m*/ public static String getErrorMessage(Throwable e) { if (e == null) { return null; } String message = e.getMessage(); // default message if (e instanceof UnknownHostException) { message = "Unknown host - " + e.getMessage(); } else if (e instanceof ClientProtocolException) { // ClientProtocolException doesn't return a message but holds the cause with the message if (e.getCause() != null) { message = e.getCause().getMessage(); } } if (StringUtils.isBlank(message)) { message = e.getClass().toString(); } return message; }
From source file:com.zimbra.cs.datasource.DataSourceManager.java
private static String generateErrorMessage(Throwable t) { StringBuilder buf = new StringBuilder(); while (t != null) { // HACK: go with JavaMail error message if (t.getClass().getName().startsWith("javax.mail.")) { String msg = t.getMessage(); return msg != null ? msg : t.toString(); }/* w ww . j av a 2 s. c o m*/ if (buf.length() > 0) { buf.append(", "); } String msg = t.getMessage(); buf.append(msg != null ? msg : t.toString()); t = t.getCause(); } return buf.toString(); }
From source file:net.greghaines.jesque.web.controller.JesqueController.java
private static ModelAndView errorModelAndView(final String viewName, final Throwable t, final HttpStatus status) { final ModelAndView model = new ModelAndView(viewName); model.addObject("errorCode", status.value()); model.addObject("errorName", toNiceCase(status.name())); model.addObject("errorType", t.getClass().getName()); model.addObject("errorMessage", t.getMessage()); model.addObject("stackTrace", JesqueUtils.createBacktrace(t).toArray(new String[0])); return model; }