Java Code Examples for org.apache.commons.lang.exception.ExceptionUtils#getCause()

The following examples show how to use org.apache.commons.lang.exception.ExceptionUtils#getCause() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TddlException.java    From tddl5 with Apache License 2.0 6 votes vote down vote up
/**
 * 为解决嵌套Exception的异常输出问题,针对无message的递归获取cause的节点,保证拿到正确的cause异常 <br/>
 * 如果自己有设置过message,以当前异常的message为准
 */
public String getMessage() {
    if (super.getMessage() != null) {
        return super.getMessage();
    } else {
        Throwable ca = this;
        do {
            Throwable c = ExceptionUtils.getCause(ca);
            if (c != null) {
                ca = c;
            } else {
                break;
            }
        } while (ca.getMessage() == null);
        return ca.getMessage();
    }
}
 
Example 2
Source File: TddlNestableRuntimeException.java    From tddl5 with Apache License 2.0 6 votes vote down vote up
/**
 * 为解决嵌套Exception的异常输出问题,针对无message的递归获取cause的节点,保证拿到正确的cause异常 <br/>
 * 如果自己有设置过message,以当前异常的message为准
 */
@Override
public String getMessage() {
    if (super.getMessage() != null) {
        return super.getMessage();
    } else if (cause != null) {
        Throwable ca = cause;
        while (this.getClass().isInstance(ca) && ca.getMessage() == null) {
            Throwable c = ExceptionUtils.getCause(ca);
            if (c != null) {
                ca = c;
            } else {
                break;
            }
        }

        if (ca != null) {
            return ca.getMessage();
        } else {
            return null;
        }
    } else {
        return null;
    }
}
 
Example 3
Source File: ExceptionUtils.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>Returns the list of <code>Throwable</code> objects in the
 * exception chain.</p>
 *
 * <p>A throwable without cause will return a list containing
 * one element - the input throwable.
 * A throwable with one cause will return a list containing
 * two elements. - the input throwable and the cause throwable.
 * A <code>null</code> throwable will return a list of size zero.</p>
 *
 * <p>This method handles recursive cause structures that might
 * otherwise cause infinite loops. The cause chain is processed until
 * the end is reached, or until the next item in the chain is already
 * in the result set.</p>
 *
 * @param throwable  the throwable to inspect, may be null
 * @return the list of throwables, never null
 * @since Commons Lang 2.2
 */
public static List getThrowableList(Throwable throwable) {
    List list = new ArrayList();
    while (throwable != null && list.contains(throwable) == false) {
        list.add(throwable);
        throwable = ExceptionUtils.getCause(throwable);
    }
    return list;
}
 
Example 4
Source File: ExceptionUtils.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>Returns the list of <code>Throwable</code> objects in the
 * exception chain.</p>
 *
 * <p>A throwable without cause will return a list containing
 * one element - the input throwable.
 * A throwable with one cause will return a list containing
 * two elements. - the input throwable and the cause throwable.
 * A <code>null</code> throwable will return a list of size zero.</p>
 *
 * <p>This method handles recursive cause structures that might
 * otherwise cause infinite loops. The cause chain is processed until
 * the end is reached, or until the next item in the chain is already
 * in the result set.</p>
 *
 * @param throwable  the throwable to inspect, may be null
 * @return the list of throwables, never null
 * @since Commons Lang 2.2
 */
public static List getThrowableList(Throwable throwable) {
    List list = new ArrayList();
    while (throwable != null && list.contains(throwable) == false) {
        list.add(throwable);
        throwable = ExceptionUtils.getCause(throwable);
    }
    return list;
}
 
Example 5
Source File: ExceptionUtils.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>Returns the list of <code>Throwable</code> objects in the
 * exception chain.</p>
 *
 * <p>A throwable without cause will return a list containing
 * one element - the input throwable.
 * A throwable with one cause will return a list containing
 * two elements. - the input throwable and the cause throwable.
 * A <code>null</code> throwable will return a list of size zero.</p>
 *
 * <p>This method handles recursive cause structures that might
 * otherwise cause infinite loops. The cause chain is processed until
 * the end is reached, or until the next item in the chain is already
 * in the result set.</p>
 *
 * @param throwable  the throwable to inspect, may be null
 * @return the list of throwables, never null
 * @since Commons Lang 2.2
 */
public static List getThrowableList(Throwable throwable) {
    List list = new ArrayList();
    while (throwable != null && list.contains(throwable) == false) {
        list.add(throwable);
        throwable = ExceptionUtils.getCause(throwable);
    }
    return list;
}