Class UncheckedException

  • All Implemented Interfaces:
    Serializable

    public final class UncheckedException
    extends RuntimeException
    An unchecked exception to efficiently wrap checked Throwables.

    This exception does not carry a message or stack trace of its own; most of its methods proxy through to those of its 'cause', so that it does not appear as an extra layer of indirection in a typical stack trace. It has one specific new method, unwrap, to obtain the actual wrapped throwable (as getCause is proxied to return the wrapped throwable's cause).

    See Also:
    Serialized Form
    • Method Detail

      • unchecked

        public static RuntimeException unchecked​(Exception e)
        Return the exception e as a RuntimeException.

        Intended for use in a throw unchecked(e); construct. If e is already an unchecked exception, it is simply returned; otherwise, it is returned wrapped.

        Returns:
        the supplied exception, possibly wrapped
      • unchecked

        public static RuntimeException unchecked​(Throwable t)
        Return the throwable t as a RuntimeException.

        Intended for use in a throw unchecked(t); construct. If t is already a RuntimeException, it is simply returned; if it is an Error, it is thrown from this method; otherwise, it is returned wrapped.

        Returns:
        the supplied exception, possibly wrapped
        Throws:
        Error - or a subclass, if that's what t is
      • unwrap

        public Throwable unwrap()
        Return the Throwable that this UncheckedException wraps.

        The familiar inherited methods proxy through to the wrapped throwable (so getCause will return its cause, and so on); this distinct method is provided to undo the wrapping.

        Returns:
        the wrapped Throwable