List of usage examples for java.lang Throwable getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:de.huxhorn.lilith.Lilith.java
@SuppressWarnings({ "ThrowableResultOfMethodCallIgnored" }) private static void appendStatus(StringBuilder builder, Status status, int indent) { int levelCode = status.getLevel(); appendIndent(builder, indent);/*from w w w. j a va2s .c om*/ if (levelCode >= 0 && levelCode < STATUS_TEXT.length) { builder.append(STATUS_TEXT[levelCode]); } builder.append(status.getMessage()).append('\n'); Throwable t = status.getThrowable(); while (t != null) { appendIndent(builder, indent + 1); builder.append(t.getClass().getName()); String message = t.getMessage(); if (message != null) { builder.append(": ").append(message); } builder.append('\n'); // probably check for causes, too t = t.getCause(); } if (status.hasChildren()) { Iterator<Status> children = status.iterator(); while (children.hasNext()) { appendStatus(builder, children.next(), indent + 1); } } }
From source file:fr.xebia.management.statistics.ServiceStatistics.java
/** * Returns <code>true</code> if the given <code>throwable</code> or one of * its cause is an instance of one of the given <code>throwableTypes</code>. *///from w w w. j a v a 2 s .c o m public static boolean containsThrowableOfType(Throwable throwable, Class<?>... throwableTypes) { List<Throwable> alreadyProcessedThrowables = new ArrayList<Throwable>(); while (true) { if (throwable == null) { // end of the list of causes return false; } else if (alreadyProcessedThrowables.contains(throwable)) { // infinite loop in causes return false; } else { for (Class<?> throwableType : throwableTypes) { if (throwableType.isAssignableFrom(throwable.getClass())) { return true; } } alreadyProcessedThrowables.add(throwable); throwable = throwable.getCause(); } } }
From source file:com.jxva.exception.ExceptionUtil.java
/** * Gets a short message summarising the exception. * <p>// w w w.jav a 2 s . co m * The message returned is of the form * {ClassNameWithoutPackage}: {ThrowableMessage} * * @param th the throwable to get a message for, null returns empty string * @return the message, non-null * @since Commons Lang 2.2 */ public static String getMessage(Throwable th) { if (th == null) { return ""; } String clsName = th.getClass().getName(); String msg = th.getMessage(); return clsName + ": " + (msg == null ? "" : msg); }
From source file:com.jxva.exception.ExceptionUtil.java
/** * <p>Finds a <code>Throwable</code> by method name.</p> * * @param throwable the exception to examine * @param methodName the name of the method to find and invoke * @return the wrapped exception, or <code>null</code> if not found */// w ww . ja v a 2 s . c om private static Throwable getCauseUsingMethodName(Throwable throwable, String methodName) { Method method = null; try { method = throwable.getClass().getMethod(methodName); } catch (NoSuchMethodException ignored) { // exception ignored } catch (SecurityException ignored) { // exception ignored } if (method != null && Throwable.class.isAssignableFrom(method.getReturnType())) { try { return (Throwable) method.invoke(throwable, ArrayUtil.EMPTY_OBJECT_ARRAY); } catch (IllegalAccessException ignored) { // exception ignored } catch (IllegalArgumentException ignored) { // exception ignored } catch (InvocationTargetException ignored) { // exception ignored } } return null; }
From source file:de.tuberlin.uebb.jbop.exception.JBOPClassExceptionTest.java
/** * Test creation of {@link JBOPClassException}. *//*from ww w .j a v a 2 s .c o m*/ @Test public void testJBOPClassException() { final JBOPClassException jBOPClassException = new JBOPClassException(message, cause); try { throw jBOPClassException; } catch (final Throwable jce) { assertEquals(jce.getClass().getSimpleName() + ": " + message, ExceptionUtils.getMessage(jce)); assertEquals(cause, ExceptionUtils.getRootCause(jce)); } }
From source file:com.yunshan.cloudstack.vmware.util.VmwareHelper.java
public static String getExceptionMessage(Throwable e, boolean printStack) { // TODO: in vim 5.1, exceptions do not have a base exception class, // MethodFault becomes a FaultInfo that we can only get // from individual exception through getFaultInfo, so we have to use // reflection here to get MethodFault information. try {/*from ww w . ja va 2 s .co m*/ Class<? extends Throwable> cls = e.getClass(); Method mth = cls.getDeclaredMethod("getFaultInfo", (Class<?>) null); if (mth != null) { Object fault = mth.invoke(e, (Object[]) null); if (fault instanceof MethodFault) { final StringWriter writer = new StringWriter(); writer.append("Exception: " + fault.getClass().getName() + "\n"); writer.append("message: " + ((MethodFault) fault).getFaultMessage() + "\n"); if (printStack) { writer.append("stack: "); e.printStackTrace(new PrintWriter(writer)); } return writer.toString(); } } } catch (Exception ex) { } return ExceptionUtil.toString(e, printStack); }
From source file:com.serli.chell.framework.exception.handler.ExceptionHandler.java
public boolean accept(Throwable exception) { return ClassUtils.isDescendantOf(exception.getClass(), matchExceptionClass); }
From source file:cn.remex.core.util.ObjectUtils.java
/** * Check whether the given exception is compatible with the exceptions * declared in a throws clause./*from ww w. jav a 2 s . com*/ * @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(final Throwable ex, final Class<?>[] declaredExceptions) { if (!isCheckedException(ex)) { return true; } if (declaredExceptions != null) { for (Class<?> declaredException : declaredExceptions) { if (declaredException.isAssignableFrom(ex.getClass())) { return true; } } } return false; }
From source file:de.femodeling.e4.server.internal.exception.ServiceExceptionAdvice.java
/** * @param throwable//w ww . ja va 2s. com * The {@link Throwable} cause * @throws Throwable */ public void afterThrowing(Throwable throwable) throws Throwable { logger.info("Exception of type <" + throwable.getClass().getName() + " traced"); if (throwable instanceof ServiceException) { throw throwable; } if (throwable instanceof SessionExpiredException) { throw throwable; } throw new ServiceException(throwable); }
From source file:h2o.common.spring.util.ObjectUtils.java
/** * Check whether the given exception is compatible with the exceptions * declared in a throws clause.//w w w.ja va 2s. co m * @param ex the exception to checked * @param declaredExceptions the exceptions declared in the throws clause * @return whether the given exception is compatible */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static boolean isCompatibleWithThrowsClause(Throwable ex, Class[] declaredExceptions) { if (!isCheckedException(ex)) { return true; } if (declaredExceptions != null) { int i = 0; while (i < declaredExceptions.length) { if (declaredExceptions[i].isAssignableFrom(ex.getClass())) { return true; } i++; } } return false; }