View Javadoc
1   package com.atlassian.plugin.event;
2   
3   import com.atlassian.plugin.PluginException;
4   
5   import java.util.Collections;
6   import java.util.List;
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      private final List<Throwable> allCauses;
18  
19      /**
20       * Constructs a NotificationException with a single caused by Exception thrown by a Listener.
21       *
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          super(cause);
29          allCauses = Collections.singletonList(cause);
30      }
31  
32      /**
33       * Constructs a NotificationException with a List of the Exceptions that were thrown by the Listeners.
34       *
35       * @param causes all Exceptions that were thrown by the Listeners.
36       *               (the full list will be available by the {@link #getAllCauses()} method;
37       *               the {@link #getCause()} method will just return the first cause in the list.
38       * @throws NullPointerException      If a null List is passed.
39       * @throws IndexOutOfBoundsException If an empty List is passed.
40       */
41      public NotificationException(final List<Throwable> causes) {
42          super(causes.get(0));
43          this.allCauses = Collections.unmodifiableList(causes);
44      }
45  
46      public List<Throwable> getAllCauses() {
47          return allCauses;
48      }
49  }