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:org.kynx.pentaho.multen.MultenExceptionMapper.java

private String getCode(Throwable e) {
    String name = e.getClass().getName();
    if (e instanceof IMultenException || statusMap.containsKey(name)) {
        return e.getClass().getSimpleName();
    }//www  .  j  av a 2 s  .  c  o  m
    return CODE_APPEXCEPTION;
}

From source file:com.evolveum.midpoint.test.IntegrationTestTools.java

public static void display(String title, Throwable e) {
    String stackTrace = ExceptionUtils.getStackTrace(e);
    System.out.println(OBJECT_TITLE_OUT_PREFIX + title + ": " + e.getClass() + " " + e.getMessage());
    System.out.println(stackTrace);
    LOGGER.debug("{}{}: {} {}\n{}",
            new Object[] { OBJECT_TITLE_LOG_PREFIX, title, e.getClass(), e.getMessage(), stackTrace });
}

From source file:org.kynx.pentaho.multen.MultenExceptionMapper.java

private int getStatus(Throwable e) {
    String name = e.getClass().getName();
    if (statusMap.containsKey(name)) {
        return statusMap.get(name);
    } else if (e instanceof WebApplicationException) {
        WebApplicationException ex = (WebApplicationException) e;
        return ex.getResponse().getStatus();
    }// www. jav a2 s. c o  m
    return STATUS_ERROR;
}

From source file:kr.okplace.job.support.StepExecutionApplicationEventAdvice.java

public void onError(JoinPoint jp, StepExecution stepExecution, Throwable t) {
    String msg = "Error in: " + jp.toShortString() + " with: " + stepExecution + " (" + t.getClass() + ":"
            + t.getMessage() + ")";
    publish(jp.getTarget(), msg);//  w w  w.  jav  a2 s.com
}

From source file:com.cloud.hypervisor.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 w  ww.j a v a  2s  .c om
        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) {
        s_logger.info("[ignored]" + "failed toi get message for exception: " + e.getLocalizedMessage());
    }

    return ExceptionUtil.toString(e, printStack);
}

From source file:com.kamuda.common.exception.ExceptionUtils.java

/**
 * <p>Checks whether this <code>Throwable</code> class can store a cause.</p>
 * /*from   w ww . j  a  v  a2  s  .c  o  m*/
 * <p>This method does <b>not</b> check whether it actually does store a cause.<p>
 *
 * @param throwable  the <code>Throwable</code> to examine, may be null
 * @return boolean <code>true</code> if nested otherwise <code>false</code>
 * @since 2.0
 */
public static boolean isNestedThrowable(Throwable throwable) {
    if (throwable == null) {
        return false;
    }

    if (throwable instanceof Nestable) {
        return true;
    } else if (throwable instanceof SQLException) {
        return true;
    } else if (throwable instanceof InvocationTargetException) {
        return true;
    } else if (isThrowableNested()) {
        return true;
    }

    Class cls = throwable.getClass();
    for (int i = 0, isize = CAUSE_METHOD_NAMES.length; i < isize; i++) {
        try {
            Method method = cls.getMethod(CAUSE_METHOD_NAMES[i], null);
            if (method != null && Throwable.class.isAssignableFrom(method.getReturnType())) {
                return true;
            }
        } catch (NoSuchMethodException ignored) {
        } catch (SecurityException ignored) {
        }
    }

    try {
        Field field = cls.getField("detail");
        if (field != null) {
            return true;
        }
    } catch (NoSuchFieldException ignored) {
    } catch (SecurityException ignored) {
    }

    return false;
}

From source file:com.haulmont.cuba.gui.exception.AbstractGenericExceptionHandler.java

@Override
public boolean handle(Throwable exception, WindowManager windowManager) {
    //noinspection unchecked
    List<Throwable> list = ExceptionUtils.getThrowableList(exception);
    for (Throwable throwable : list) {
        if (classNames.contains(throwable.getClass().getName())
                && canHandle(throwable.getClass().getName(), throwable.getMessage(), throwable)) {
            doHandle(throwable.getClass().getName(), throwable.getMessage(), throwable, windowManager);
            return true;
        }/*from   w ww  . j  a v a 2  s .  c om*/
        if (throwable instanceof RemoteException) {
            RemoteException remoteException = (RemoteException) throwable;
            for (RemoteException.Cause cause : remoteException.getCauses()) {
                if (classNames.contains(cause.getClassName())
                        && canHandle(cause.getClassName(), cause.getMessage(), cause.getThrowable())) {
                    doHandle(cause.getClassName(), cause.getMessage(), cause.getThrowable(), windowManager);
                    return true;
                }
            }
        }
    }
    return false;
}

From source file:com.haulmont.cuba.desktop.exception.AbstractExceptionHandler.java

@Override
public boolean handle(Thread thread, Throwable exception) {
    //noinspection unchecked
    List<Throwable> list = ExceptionUtils.getThrowableList(exception);
    for (Throwable throwable : list) {
        if (classNames.contains(throwable.getClass().getName())
                && canHandle(throwable.getClass().getName(), throwable.getMessage(), throwable)) {
            doHandle(thread, throwable.getClass().getName(), throwable.getMessage(), throwable);
            return true;
        }/*from w w  w  .jav a  2s .  co  m*/
        if (throwable instanceof RemoteException) {
            RemoteException remoteException = (RemoteException) throwable;
            for (RemoteException.Cause cause : remoteException.getCauses()) {
                if (classNames.contains(cause.getClassName())
                        && canHandle(throwable.getClass().getName(), throwable.getMessage(), throwable)) {
                    doHandle(thread, cause.getClassName(), cause.getMessage(), cause.getThrowable());
                    return true;
                }
            }
        }
    }
    return false;
}

From source file:com.yy.kunka.core.workflow.error.DefaultErrorHandler.java

public void handleError(ProcessContext context, Throwable th) throws WorkflowException {
    context.stopProcess();// w  ww  . j ava  2 s.  c o m

    boolean shouldLog = true;
    Throwable cause = th;
    while (true) {
        if (unloggedExceptionClasses.contains(cause.getClass().getName())) {
            shouldLog = false;
            break;
        }
        cause = cause.getCause();
        if (cause == null) {
            break;
        }
    }
    if (shouldLog) {
        LOG.info("An error occurred during the workflow", th);
    }
    throw new WorkflowException(th);
}

From source file:com.haulmont.cuba.web.exception.AbstractExceptionHandler.java

@Override
public boolean handle(ErrorEvent event, App app) {
    Throwable exception = event.getThrowable();
    //noinspection unchecked
    List<Throwable> list = ExceptionUtils.getThrowableList(exception);
    for (Throwable throwable : list) {
        if (classNames.contains(throwable.getClass().getName())
                && canHandle(throwable.getClass().getName(), throwable.getMessage(), throwable)) {
            doHandle(app, throwable.getClass().getName(), throwable.getMessage(), throwable);
            return true;
        }// ww w  .  j  a v  a  2  s .c o  m
        if (throwable instanceof RemoteException) {
            RemoteException remoteException = (RemoteException) throwable;
            for (RemoteException.Cause cause : remoteException.getCauses()) {
                if (classNames.contains(cause.getClassName())
                        && canHandle(cause.getClassName(), cause.getMessage(), cause.getThrowable())) {
                    doHandle(app, cause.getClassName(), cause.getMessage(), cause.getThrowable());
                    return true;
                }
            }
        }
    }
    return false;
}