Example usage for java.lang Throwable getClass

List of usage examples for java.lang Throwable getClass

Introduction

In this page you can find the example usage for java.lang Throwable getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:com.myee.tarot.core.exception.ExceptionHelper.java

public static <G extends Throwable, J extends RuntimeException> RuntimeException refineException(
        Class<G> refineType, Class<J> wrapType, String message, Throwable e) {
    if (refineType.isAssignableFrom(e.getClass())) {
        return wrapException(e, wrapType, message);
    }/*w ww . j  a  v  a  2s  . co m*/
    if (e.getCause() != null) {
        return refineException(refineType, wrapType, message, e.getCause());
    }
    if (e instanceof UndeclaredThrowableException) {
        return refineException(refineType, wrapType, message,
                ((UndeclaredThrowableException) e).getUndeclaredThrowable());
    }
    if (e instanceof InvocationTargetException) {
        return refineException(refineType, wrapType, message,
                ((InvocationTargetException) e).getTargetException());
    }
    return wrapException(e, wrapType, message);
}

From source file:com.myee.tarot.core.exception.ExceptionHelper.java

public static <G extends Throwable, J extends RuntimeException> void processException(Class<G> refineType,
        Class<J> wrapType, String message, Throwable e) throws G {
    if (refineType.isAssignableFrom(e.getClass())) {
        throw (G) e;
    }//from w w w . j a v  a  2  s . c om
    if (e.getCause() != null) {
        processException(refineType, wrapType, message, e.getCause());
    }
    if (e instanceof UndeclaredThrowableException) {
        processException(refineType, wrapType, message,
                ((UndeclaredThrowableException) e).getUndeclaredThrowable());
    }
    if (e instanceof InvocationTargetException) {
        processException(refineType, wrapType, message, ((InvocationTargetException) e).getTargetException());
    }
    throw wrapException(e, wrapType, message);
}

From source file:com.mirth.connect.util.ErrorMessageBuilder.java

public static String buildErrorResponse(String customMessage, Throwable e) {
    String responseException = new String();
    if (e != null) {
        responseException = " [" + e.getClass().getSimpleName() + ": " + e.getMessage() + "]";
    }//from   ww  w.  j a v  a2s  .co  m

    return customMessage + responseException;
}

From source file:it.geosolutions.geostore.core.security.password.SecurityUtils.java

/**
 * Spring Secruity 3.x drops the common base security exception
 * class SpringSecurityException, now the test is based on the package
 * name//w w  w  .j a  va 2 s  . c o m
 * 
 * @param t, the exception to check
 * @return true if the exception is caused by Spring Security
 */
public static boolean isSecurityException(Throwable t) {
    return t != null && t.getClass().getPackage().getName().startsWith("org.springframework.security");
}

From source file:com.github.rnewson.couchdb.lucene.Utils.java

public static String throwableToJSON(final Throwable t) {
    return error(
            t.getMessage() == null ? "Unknown error" : String.format("%s: %s", t.getClass(), t.getMessage()));
}

From source file:ExceptionUtils.java

/**
 * Set the cause of the Exception.  Will detect if this is not allowed.
 * @param onObject/*from www  . j  a v a  2 s.  c om*/
 * @param cause
 */
public static void setCause(Throwable onObject, Throwable cause) {
    if (causesAllowed) {
        try {
            Method method = onObject.getClass().getMethod("initCause", new Class[] { Throwable.class });
            method.invoke(onObject, new Object[] { cause });
        } catch (RuntimeException e) {
            throw e;
        } catch (Exception e) {
            causesAllowed = false;
        }
    }
}

From source file:Main.java

public static <T extends Throwable> T catchException(Class<T> exceptionClass, Runnable behavior) {
    Throwable caught = null;

    try {//from  w w w . java2 s  . c om
        behavior.run();
    } catch (Throwable ex) {
        caught = ex;
    }

    if (caught != null && exceptionClass.isAssignableFrom(caught.getClass()))
        //noinspection unchecked
        return (T) caught;

    return null;
}

From source file:Main.java

/**
 * make throwable to string.// w w w . j a v  a2 s .  c  om
 */
public static String toString(Throwable throwable) {
    StringWriter stringWriter = new StringWriter();
    PrintWriter printWriter = new PrintWriter(stringWriter);
    printWriter.print(throwable.getClass().getName() + ": ");
    if (throwable.getMessage() != null) {
        printWriter.print(throwable.getMessage() + "\n");
    }
    printWriter.println();
    try {
        throwable.printStackTrace(printWriter);
        return stringWriter.toString();
    } finally {
        printWriter.close();
    }
}

From source file:mitm.application.djigzo.ws.WSExceptionUtils.java

public static String getExceptionMessage(Throwable t) {
    Throwable cause = ExceptionUtils.getRootCause(t);

    if (cause == null) {
        cause = t;// www  .  j ava  2s . c o  m
    }

    return ExceptionUtils.getRootCauseMessage(t) + ", Class: " + cause.getClass();
}

From source file:com.hula.lang.util.DotNotationUtil.java

/**
 * Uses beanutils to reflect the value of a property
 * /*from   ww  w . j  a va2s . c o  m*/
 * @param obj the object to inspect
 * @param property the property to reflect
 * @return the value of the property
 */
private static Object reflect(Object obj, String property) {
    try {
        return PropertyUtils.getProperty(obj, property);
    } catch (Throwable t) {
        logger.error("error getting property [" + t.getClass().getSimpleName() + "]", t);
        return null;
    }
}