Class ExceptionUtil

java.lang.Object
tools.jackson.databind.util.ExceptionUtil

public class ExceptionUtil extends Object
Utility methods for dealing with exceptions/throwables
Since:
2.15
  • Method Details

    • rethrowIfFatal

      public static void rethrowIfFatal(Throwable throwable) throws Error, RuntimeException
      It is important never to catch all Throwables. Some like 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.

      Parameters:
      throwable - to check
      Throws:
      Error - the input throwable if it is fatal
      RuntimeException - the input throwable if it is fatal - throws the original throwable if is a RuntimeException. Otherwise, wraps the throwable in a RuntimeException.
    • rethrowIfNoWrap

      public static <ERR extends Throwable> ERR rethrowIfNoWrap(DeserializationContext ctxt, ERR e)
      Helper method that will either throw given throwable -- if (and only if) one of following is true: 1. It is an Error 2. It is a JacksonException 3. DeserializationFeature.WRAP_EXCEPTIONS is NOT enabled AND exception is a RuntimeException -- or (otherwise) returns throwable as-is.
      Parameters:
      ctxt - Current deserialization context
      e - Exception caught to possibly re-throw
      Returns:
      Exception passed in for call chaining
      Since:
      3.1