Class ScopedWorkException

  • All Implemented Interfaces:
    java.io.Serializable

    @ProviderType
    public class ScopedWorkException
    extends java.lang.RuntimeException
    An Exception that is thrown when a piece of scoped work exits with an Exception.

    If the scope was inherited and therefore is still active when this exception is raised then the current TransactionContext will be available from the ongoingContext() method.

    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      ScopedWorkException​(java.lang.String message, java.lang.Throwable cause, TransactionContext context)
      Creates a new TransactionException with the supplied message and cause
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <T extends java.lang.Throwable>
      T
      as​(java.lang.Class<T> throwable)
      Throws the cause of this Exception as a RuntimeException the supplied Exception type.
      <A extends java.lang.Throwable,​B extends java.lang.Throwable>
      java.lang.RuntimeException
      asOneOf​(java.lang.Class<A> a, java.lang.Class<B> b)
      Throws the cause of this Exception as a RuntimeException or one of the supplied Exception types.
      <A extends java.lang.Throwable,​B extends java.lang.Throwable,​C extends java.lang.Throwable>
      java.lang.RuntimeException
      asOneOf​(java.lang.Class<A> a, java.lang.Class<B> b, java.lang.Class<C> c)
      Throws the cause of this Exception as a RuntimeException or one of the supplied Exception types.
      <A extends java.lang.Throwable,​B extends java.lang.Throwable,​C extends java.lang.Throwable,​D extends java.lang.Throwable>
      java.lang.RuntimeException
      asOneOf​(java.lang.Class<A> a, java.lang.Class<B> b, java.lang.Class<C> c, java.lang.Class<D> d)
      Throws the cause of this Exception as a RuntimeException or one of the supplied Exception types.
      java.lang.RuntimeException asRuntimeException()  
      TransactionContext ongoingContext()  
      • Methods inherited from class java.lang.Throwable

        addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
      • Methods inherited from class java.lang.Object

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

      • ScopedWorkException

        public ScopedWorkException​(java.lang.String message,
                                   java.lang.Throwable cause,
                                   TransactionContext context)
        Creates a new TransactionException with the supplied message and cause
        Parameters:
        message -
        cause -
        context -
    • Method Detail

      • ongoingContext

        public TransactionContext ongoingContext()
        Returns:
        The ongoing transaction context if the current scope was still active when this exception was raised or null otherwise. Note that this property will not be persisted during serialization.
      • asRuntimeException

        public java.lang.RuntimeException asRuntimeException()
        Returns:
        The cause of this Exception as a RuntimeException if it is one, or this otherwise
      • as

        public <T extends java.lang.Throwable> T as​(java.lang.Class<T> throwable)
                                             throws T extends java.lang.Throwable
        Throws the cause of this Exception as a RuntimeException the supplied Exception type.

        Usage is of the form:

         public void doStuff() throws IOException {
             try {
                 ...
             } catch (ScopedWorkException swe) {
                 throw swe.as(IOException.class);
             }
         }
         
        Parameters:
        throwable -
        Returns:
        This method will always throw an exception
        Throws:
        T
        T extends java.lang.Throwable
      • asOneOf

        public <A extends java.lang.Throwable,​B extends java.lang.Throwable> java.lang.RuntimeException asOneOf​(java.lang.Class<A> a,
                                                                                                                      java.lang.Class<B> b)
                                                                                                               throws A extends java.lang.Throwable,
                                                                                                                      B extends java.lang.Throwable
        Throws the cause of this Exception as a RuntimeException or one of the supplied Exception types.

        Usage is of the form:

         public void doStuff() throws IOException, ClassNotFoundException {
             try {
                 ...
             } catch (ScopedWorkException swe) {
                 throw swe.asOneOf(IOException.class, ClassNotFoundException.class);
             }
         }
         
        Parameters:
        a -
        b -
        Returns:
        This method will always throw an exception
        Throws:
        A
        B
        A extends java.lang.Throwable
      • asOneOf

        public <A extends java.lang.Throwable,​B extends java.lang.Throwable,​C extends java.lang.Throwable> java.lang.RuntimeException asOneOf​(java.lang.Class<A> a,
                                                                                                                                                          java.lang.Class<B> b,
                                                                                                                                                          java.lang.Class<C> c)
                                                                                                                                                   throws A extends java.lang.Throwable,
                                                                                                                                                          B extends java.lang.Throwable,
                                                                                                                                                          C extends java.lang.Throwable
        Throws the cause of this Exception as a RuntimeException or one of the supplied Exception types.
        Parameters:
        a -
        b -
        c -
        Returns:
        This method will always throw an exception
        Throws:
        A
        B
        A extends java.lang.Throwable
        See Also:
        asOneOf(Class, Class)
      • asOneOf

        public <A extends java.lang.Throwable,​B extends java.lang.Throwable,​C extends java.lang.Throwable,​D extends java.lang.Throwable> java.lang.RuntimeException asOneOf​(java.lang.Class<A> a,
                                                                                                                                                                                              java.lang.Class<B> b,
                                                                                                                                                                                              java.lang.Class<C> c,
                                                                                                                                                                                              java.lang.Class<D> d)
                                                                                                                                                                                       throws A extends java.lang.Throwable,
                                                                                                                                                                                              B extends java.lang.Throwable,
                                                                                                                                                                                              C extends java.lang.Throwable,
                                                                                                                                                                                              D extends java.lang.Throwable
        Throws the cause of this Exception as a RuntimeException or one of the supplied Exception types.
        Parameters:
        a -
        b -
        c -
        d -
        Returns:
        This method will always throw an exception
        Throws:
        A
        B
        C
        D
        A extends java.lang.Throwable
        See Also:
        asOneOf(Class, Class)