View Javadoc

1   package com.atlassian.plugin.event;
2   
3   import com.atlassian.plugin.PluginException;
4   
5   import java.util.List;
6   import java.util.Collections;
7   
8   /**
9    * This is used to wrap one or more exceptions thrown by Plugin Event Listeners on receiving an event.
10   *
11   * <p> {@link #getAllCauses()} will return a list with all the exceptions that were thrown by the listeners.
12   * <p> {@link #getCause()} will return just the first Exception in the list.
13   *
14   * @since 2.3.0
15   */
16  public class NotificationException extends PluginException
17  {
18      private final List<Throwable> allCauses;
19  
20      /**
21       * Constructs a NotificationException with a single caused by Exception thrown by a Listener.
22       * @param  cause the cause (which is saved for later retrieval by the {@link #getCause()} method).
23       *              (A <code>null</code> value should never be passed because this exception is only used to wrap other exceptions.)
24       * @throws NullPointerException If a null List is passed.
25       * @throws IndexOutOfBoundsException If an empty List is passed.
26       */
27      public NotificationException(final Throwable cause)
28      {
29          super(cause);
30          allCauses = Collections.singletonList(cause);
31      }
32  
33      /**
34       * Constructs a NotificationException with a List of the Exceptions that were thrown by the Listeners.
35       *
36       * @param causes all Exceptions that were thrown by the Listeners.
37       *          (the full list will be available by the {@link #getAllCauses()} method;
38       *          the {@link #getCause()} method will just return the first cause in the list.
39       * @throws NullPointerException If a null List is passed.
40       * @throws IndexOutOfBoundsException If an empty List is passed.
41       */
42      public NotificationException(final List<Throwable> causes)
43      {
44          //noinspection ThrowableResultOfMethodCallIgnored
45          super(causes.get(0));
46          this.allCauses = Collections.unmodifiableList(causes);
47      }
48  
49      public List<Throwable> getAllCauses()
50      {
51          return allCauses;
52      }
53  }