Class ExceptionUtil


  • public class ExceptionUtil
    extends java.lang.Object
    Utility methods for dealing with exceptions/throwables
    Since:
    2.15
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private ExceptionUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static <E extends java.lang.Throwable>
      void
      _sneaky​(java.lang.Throwable e)  
      private static boolean isFatal​(java.lang.Throwable throwable)
      It is important never to catch all Throwables.
      static void rethrowIfFatal​(java.lang.Throwable throwable)
      It is important never to catch all Throwables.
      static <T> T throwSneaky​(java.io.IOException e)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ExceptionUtil

        private ExceptionUtil()
    • Method Detail

      • rethrowIfFatal

        public static void rethrowIfFatal​(java.lang.Throwable throwable)
                                   throws java.lang.Error,
                                          java.lang.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:
        java.lang.Error - the input throwable if it is fatal
        java.lang.RuntimeException - the input throwable if it is fatal - throws the original throwable if is a RuntimeException. Otherwise, wraps the throwable in a RuntimeException.
      • isFatal

        private static boolean isFatal​(java.lang.Throwable throwable)
        It is important never to catch all Throwables. Some like InterruptedException should be rethrown. Based on scala.util.control.NonFatal.
        Parameters:
        throwable - to check
        Returns:
        whether the Throwable is a fatal error
      • throwSneaky

        public static <T> T throwSneaky​(java.io.IOException e)
      • _sneaky

        private static <E extends java.lang.Throwable> void _sneaky​(java.lang.Throwable e)
                                                             throws E extends java.lang.Throwable
        Throws:
        E extends java.lang.Throwable