List of usage examples for java.lang Throwable getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:it.cnr.icar.eric.client.ui.thin.OutputExceptions.java
/** * Choose a string about Throwable which ignores generic class names * * @param t Throwable of interest/*from ww w . j a v a 2 s .c o m*/ * t.getMessage() must be non-null when this method is used * @return String message about t */ private static String goodMessage(Throwable t) { String msg; String className = t.getClass().getName(); // TODO: may want to add to this list over time if ("java.lang.Error".equals(className) || "java.lang.Exception".equals(className) || "java.lang.Throwable".equals(className) || "javax.xml.bind.JAXBException".equals(className) || "javax.xml.registry.JAXRException".equals(className) || "javax.xml.registry.RegistryException".equals(className) || "javax.xml.rpc.JAXRPCException".equals(className)) { msg = t.getMessage(); } else { msg = t.toString(); } return msg; }
From source file:ObjectUtils.java
/** * Check whether the given exception is compatible with the exceptions * declared in a throws clause./*from w w w . j a v a2 s . c o m*/ * @param ex the exception to checked * @param declaredExceptions the exceptions declared in the throws clause * @return whether the given exception is compatible */ public static boolean isCompatibleWithThrowsClause(Throwable ex, Class[] declaredExceptions) { if (!isCheckedException(ex)) { return true; } if (declaredExceptions != null) { for (int i = 0; i < declaredExceptions.length; i++) { if (declaredExceptions[i].isAssignableFrom(ex.getClass())) { return true; } } } return false; }
From source file:com.siberhus.tdfl.FieldDataException.java
protected static String translate(Throwable e) { Throwable rootCause = ExceptionUtils.getRootCause(e); if (rootCause != null) { e = rootCause;/*from w w w .jav a2 s . c o m*/ } if (!StringUtils.isBlank(e.getMessage())) { return e.getMessage(); } return e.getClass().getSimpleName(); }
From source file:com.redhat.lightblue.util.metrics.DropwizardRequestMetrics.java
/** * Get to the cause we actually care about in case the bubbled up exception is a * higher level framework exception that encapsulates the stuff we really care * about./*from w ww .j a v a 2 s.c om*/ * */ private static Class<? extends Throwable> unravelReflectionExceptions(Throwable e) { while (e.getCause() != null && (e instanceof UndeclaredThrowableException || e instanceof InvocationTargetException)) { e = e.getCause(); } return e.getClass(); }
From source file:com.aptana.core.epl.downloader.RepositoryStatusHelper.java
@SuppressWarnings("rawtypes") public static Throwable unwind(Throwable t) { for (;;) {/*from w w w .j a v a 2 s . c om*/ Class tc = t.getClass(); // We don't use instanceof operator since we want // the explicit class, not subclasses. // if (tc != RuntimeException.class && tc != InvocationTargetException.class && tc != IOException.class) break; Throwable cause = t.getCause(); if (cause == null) break; String msg = t.getMessage(); if (msg != null && !msg.equals(cause.toString())) break; t = cause; } return t; }
From source file:de.micromata.genome.util.runtime.ExceptionUtils.java
/** * Rethrow an exception into Error, RuntimeException or Exception declared. If non, a RuntimeException will be used. * * @param ex the ex/*from ww w . ja va 2 s . co m*/ * @param declared the declared * @throws Exception the exception */ public static void wrappException(Throwable ex, Class<? extends Exception>... declared) throws Exception { if (ex instanceof Error) { throw (Error) ex; } if (ex instanceof RuntimeException) { throw (RuntimeException) ex; } for (Class<? extends Exception> ce : declared) { if (ce.isAssignableFrom(ex.getClass()) == true) { throw (Exception) ex; } } throw new RuntimeException(ex); }
From source file:edu.uci.ics.asterix.result.ResultUtils.java
/** * Extract the message in the root cause of the stack trace: * * @param e//www. ja v a 2 s . c o m * @return error message string. */ private static String extractErrorMessage(Throwable e) { Throwable cause = getRootCause(e); String fullyQualifiedExceptionClassName = cause.getClass().getName(); String[] hierarchySplits = fullyQualifiedExceptionClassName.split("\\."); //try returning the class without package qualification String exceptionClassName = hierarchySplits[hierarchySplits.length - 1]; String localizedMessage = cause.getLocalizedMessage(); if (localizedMessage == null) { localizedMessage = "Internal error. Please check instance logs for further details."; } return localizedMessage + " [" + exceptionClassName + "]"; }
From source file:com.evolveum.midpoint.util.logging.LoggingUtils.java
private static void logExceptionInternal(Level first, Level second, Trace LOGGER, String message, Throwable ex, Object... objects) {//from w w w . ja v a 2 s . c o m Validate.notNull(LOGGER, "Logger can't be null."); Validate.notNull(ex, "Exception can't be null."); List<Object> args = new ArrayList<>(); args.addAll(Arrays.asList(objects)); args.add(ex.getMessage() + " (" + ex.getClass() + ")"); if (!first.equals(second)) { log(LOGGER, first, message + ", reason: {}", args.toArray()); } // Add exception to the list. It will be the last argument without {} in the message, // therefore the stack trace will get logged args.add(ex); log(LOGGER, second, message + ".", args.toArray()); }
From source file:de.alpharogroup.exception.ExceptionExtensions.java
/** * Gets the stack trace elements from the given Throwable and returns a {@link String} object * from it.//from ww w. j a va 2s . c om * * @param throwable * the throwable * @return the stack trace elements */ public static String getStackTraceElements(Throwable throwable) { StringWriter sw = null; PrintWriter pw = null; String stacktrace = "throwable is null..."; if (throwable != null) { try { sw = new StringWriter(); pw = new PrintWriter(sw); pw.println(throwable.getClass().toString()); while (throwable != null) { pw.println(throwable); final StackTraceElement[] stackTraceElements = throwable.getStackTrace(); for (final StackTraceElement stackTraceElement : stackTraceElements) { pw.println("\tat " + stackTraceElement); } throwable = throwable.getCause(); if (throwable != null) { pw.println("Caused by:\r\n"); } } stacktrace = sw.toString(); } finally { StreamExtensions.closeWriter(sw); StreamExtensions.closeWriter(pw); } } return stacktrace; }
From source file:tools.xor.util.ClassUtil.java
public static RuntimeException wrapRun(Exception e) { if (InvocationTargetException.class.isAssignableFrom(e.getClass())) { InvocationTargetException ite = (InvocationTargetException) e; Throwable cause = ite.getCause(); if (cause != null && Exception.class.isAssignableFrom(cause.getClass())) e = (Exception) cause; }//from w w w. j av a 2 s. co m if (RuntimeException.class.isAssignableFrom(e.getClass())) return (RuntimeException) e; else return new RuntimeException(e); }