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

com.infomaximum.platform.utils.ExceptionUtils Maven / Gradle / Ivy

There is a newer version: 0.1.15p24
Show newest version
package com.infomaximum.platform.utils;

import com.infomaximum.platform.exception.PlatformException;
import com.infomaximum.platform.exception.runtime.PlatformRuntimeException;

import java.util.ArrayList;
import java.util.List;

public class ExceptionUtils {

    public static RuntimeException coercionRuntimeException(Throwable throwable) {
        if (throwable instanceof PlatformException) {
            throw new PlatformRuntimeException((PlatformException) throwable);
        } else if (throwable instanceof RuntimeException) {
            return (RuntimeException) throwable;
        } else {
            return new RuntimeException(throwable);
        }
    }

    /**
     * 

Returns the list of {@code Throwable} objects in the * exception chain.

* *

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} throwable will return a list of size zero.

* *

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.

* * @param throwable the throwable to inspect, may be null * @return the list of throwables, never null * @since 2.2 */ public static List getThrowableList(Throwable throwable) { final List list = new ArrayList<>(); while (throwable != null && !list.contains(throwable)) { list.add(throwable); throwable = throwable.getCause(); } return list; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy