Class WrappedException

  • All Implemented Interfaces:
    Serializable

    public final class WrappedException
    extends RuntimeException
    Encapsulates checked Exception inside a RuntimeException. Inspired by gnu.mapping.WrappedException.
    Author:
    npiedeloup
    See Also:
    Serialized Form
    • Method Detail

      • wrap

        public static RuntimeException wrap​(Throwable th)
        Coerces argument to a RuntimeException. Re-throws as a non-checked exception. This method never returns, in spite of the return type. This allows the call to be written as: throw WrappedExcepton.rethrow(th) so javac and the verifier can know the code doesn't return.
        Parameters:
        th - Cause exception
        Returns:
        RuntimeException runtime
      • wrap

        public static RuntimeException wrap​(Throwable th,
                                            String msg,
                                            Object... params)
        Coerces argument to a RuntimeException. Re-throw as a non-checked exception. This method never returns, in spite of the return type. This allows the call to be written as: throw WrappedExcepton.rethrow(th) so javac and the verifier can know the code doesn't return.
        Parameters:
        th - Cause exception
        msg - Context message
        params - Context message params
        Returns:
        RuntimeException runtime
      • unwrap

        public Throwable unwrap()
        Gets the orginal exception.
        Returns:
        the orginal exception that has been wrapped