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

com.fasterxml.jackson.databind.util.ExceptionUtil Maven / Gradle / Ivy

Go to download

Easy Redis Java client and Real-Time Data Platform. Valkey compatible. Sync/Async/RxJava3/Reactive API. Client side caching. Over 50 Redis based Java objects and services: JCache API, Apache Tomcat, Hibernate, Spring, Set, Multimap, SortedSet, Map, List, Queue, Deque, Semaphore, Lock, AtomicLong, Map Reduce, Bloom filter, Scheduler, RPC

There is a newer version: 3.40.2
Show newest version
package com.fasterxml.jackson.databind.util;

import java.io.IOException;

/**
 * Utility methods for dealing with exceptions/throwables
 *
 * @since 2.15
 */
public class ExceptionUtil {
    private ExceptionUtil() {}

    /**
     * It is important never to catch all Throwables. Some like
     * {@link InterruptedException} should be rethrown. Based on
     * scala.util.control.NonFatal.
     *
     * This method should be used with care.
     * 

* If the Throwable is fatal, it is rethrown, otherwise, this method just returns. * The input throwable is thrown if it is an Error or a RuntimeException. * Otherwise, the method wraps the throwable in a RuntimeException and throws that. *

* * @param throwable to check * @throws Error the input throwable if it is fatal * @throws RuntimeException the input throwable if it is fatal - throws the original throwable * if is a RuntimeException. Otherwise, wraps the throwable in a RuntimeException. */ public static void rethrowIfFatal(Throwable throwable) throws Error, RuntimeException { if (isFatal(throwable)) { if (throwable instanceof Error) { throw (Error) throwable; } if (throwable instanceof RuntimeException) { throw (RuntimeException) throwable; } throw new RuntimeException(throwable); } } /** * It is important never to catch all Throwables. Some like * {@link InterruptedException} should be rethrown. Based on * scala.util.control.NonFatal. * * @param throwable to check * @return whether the Throwable is a fatal error */ private static boolean isFatal(Throwable throwable) { return (throwable instanceof VirtualMachineError || throwable instanceof ThreadDeath || throwable instanceof InterruptedException || throwable instanceof ClassCircularityError || throwable instanceof ClassFormatError || throwable instanceof IncompatibleClassChangeError || throwable instanceof BootstrapMethodError || throwable instanceof VerifyError ); } public static T throwSneaky(IOException e) { _sneaky(e); return null; // never gets here, needed for compiler tho } @SuppressWarnings("unchecked") private static void _sneaky(Throwable e) throws E { throw (E) e; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy