Class ScopedWorkException

java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
org.osgi.service.transaction.control.ScopedWorkException
All Implemented Interfaces:
Serializable

@ProviderType public class ScopedWorkException extends 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:
  • Constructor Details

    • ScopedWorkException

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

    • 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 RuntimeException asRuntimeException()
      Returns:
      The cause of this Exception as a RuntimeException if it is one, or this otherwise
    • as

      public <T extends Throwable> T as(Class<T> throwable) throws T
      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
    • asOneOf

      public <A extends Throwable, B extends Throwable> RuntimeException asOneOf(Class<A> a, Class<B> b) throws A, B
      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
    • asOneOf

      public <A extends Throwable, B extends Throwable, C extends Throwable> RuntimeException asOneOf(Class<A> a, Class<B> b, Class<C> c) throws A, B, C
      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
      C extends Throwable
      See Also:
    • asOneOf

      public <A extends Throwable, B extends Throwable, C extends Throwable, D extends Throwable> RuntimeException asOneOf(Class<A> a, Class<B> b, Class<C> c, Class<D> d) throws A, B, C, D
      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
      See Also: