All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.znerd.util.ExceptionUtils Maven / Gradle / Ivy

// See the COPYRIGHT file for copyright and license information
package org.znerd.util;

/**
 * Utility functions related to exceptions.
 */
public final class ExceptionUtils {

    /**
     * Determines the root cause for the specified exception.
     * 
     * @param exception the exception to determine the root cause for, can be null.
     * @return the root cause exception, can be null.
     */
    public static Throwable getRootCause(Throwable exception) {

        if (exception == null) {
            return null;
        }

        Throwable cause = exception.getCause();
        while (cause != null) {
            exception = cause;
            cause = exception.getCause();
        }

        return exception;
    }

    private ExceptionUtils() {
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy