View Javadoc
1   package com.atlassian.sal.api.i18n;
2   
3   import com.atlassian.annotations.Internal;
4   import com.atlassian.annotations.PublicApi;
5   
6   /**
7    * Thrown if the application decides that the attempted operation is not allowed for some reason.
8    * <p>
9    * This Exception should normally be used for "expected" errors where it is meaningful to display the error message
10   * to the end user.
11   * <p>
12   * Host applications throwing this Exception are expected to localise the message into the locale of the currently
13   * logged in user. Consumers catching this Exception are encouraged to use {@link #getLocalizedMessage()} in order
14   * to get the translated error message.
15   *
16   * @since 3.0
17   */
18  @PublicApi
19  public class InvalidOperationException extends Exception {
20      private final String localizedMessage;
21  
22      @Internal // Constructor is for host apps, not plugin devs
23      public InvalidOperationException(String message, String localizedMessage) {
24          super(message);
25          this.localizedMessage = localizedMessage;
26      }
27  
28      /**
29       * Returns the error message in the locale of the currently logged in user.
30       * <p>
31       * If no user is logged in, this should use the default locale for the host application.
32       *
33       * @return the error message in the locale of the currently logged in user.
34       * @see #getMessage()
35       */
36      @Override
37      public String getLocalizedMessage() {
38          return localizedMessage;
39      }
40  }