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 {
21 private final String localizedMessage;
22
23 @Internal // Constructor is for host apps, not plugin devs
24 public InvalidOperationException(String message, String localizedMessage)
25 {
26 super(message);
27 this.localizedMessage = localizedMessage;
28 }
29
30 /**
31 * Returns the error message in the locale of the currently logged in user.
32 * <p>
33 * If no user is logged in, this should use the default locale for the host application.
34 *
35 * @return the error message in the locale of the currently logged in user.
36 *
37 * @see #getMessage()
38 */
39 @Override
40 public String getLocalizedMessage()
41 {
42 return localizedMessage;
43 }
44 }