@PublicApi public class StructureException extends Exception
StructureException
can be thrown for different causes that involve Structure plugin. It usually means that the
operation that is traced back to the user's action cannot be performed and should be reported as an error.
Each exception is associated with a specific value from enumeration StructureError
. Exception may also
carry additional message and information about affected structure, view, item or row. The general method
Throwable.getMessage()
, returns all information included with the exception, except for the stack trace and cause.
To display an error on the user interface: use getLocalizedMessage()
or getLocalizedMessage(ApplicationUser)
to get a human-friendly error in the user's locale. However, in many cases the error message will not be localized
and the result of getLocalizedMessage()
will contain the problem description in English.
So for the best result, you should check isLocalized()
method and if exception is not localized, use some wrapper text to display the error to the user in a good way:
Java code: try { ... } catch (StructureException e) { if (e.isLocalized()) { setDisplayedError(e.getLocalizedMessage()); } else { setDisplayedError(getText("my.errors.structure-error", e.getLocalizedMessage())); } }
An instance of StructureException
may be created by using one of the available constructors, but
it might be more convenient to start from StructureError
and use chained builder commands, ending with
message specification:
throw StructureErrors.GENERIC_ERROR.withMessage("cannot foo bar"); ... throw StructureErrors.INVALID_JQL.causedBy(caughtException).forStructure(id).withoutMessage(); ... throw StructureErrors.VIEW_EDIT_DENIED.forView(id).withLocalizedMessage("error.view.edit.denied", id, name);
StructureError
,
Serialized FormModifier and Type | Class and Description |
---|---|
static class |
StructureException.Builder
A builder for
StructureException . |
Modifier | Constructor and Description |
---|---|
|
StructureException(StructureError error)
Constructs an instance of exception.
|
|
StructureException(StructureError error,
Long structure)
Constructs an instance of exception.
|
|
StructureException(StructureError error,
Long structure,
Long row)
Constructs an instance of exception.
|
|
StructureException(StructureError error,
Long structure,
Long row,
Long view)
Constructs an instance of exception.
|
|
StructureException(StructureError error,
Long structure,
Long row,
Long view,
String message)
Constructs an instance of exception.
|
|
StructureException(StructureError error,
Long structure,
Long row,
String message)
Constructs an instance of exception.
|
|
StructureException(StructureError error,
Long structure,
Long row,
String message,
Throwable cause)
Constructs an instance of exception.
|
|
StructureException(StructureError error,
String message)
Constructs an instance of exception.
|
protected |
StructureException(StructureError error,
Throwable cause,
Long structure,
Long view,
Long row,
ItemIdentity item,
String message,
String messageKey,
Object... messageParameters)
Constructs an instance of this exception.
|
Modifier and Type | Method and Description |
---|---|
I18nText |
asI18nText() |
StructureError |
getError()
Returns the error value associated with the exception.
|
ItemIdentity |
getItem()
Returns related item, or null if no item is related.
|
String |
getLocalizedMessage()
Gets the localized message about the problem in the current user's locale.
|
String |
getLocalizedMessage(ApplicationUser user)
Gets the localized message about the problem in the given user's locale.
|
String |
getProblemDetails()
Returns the part of
Throwable.getMessage() that corresponds to the original description of the problem. |
long |
getRow()
Returns related row, or 0 if no row is related.
|
long |
getStructure()
Returns related structure, or 0 if no structure is related.
|
long |
getView()
Returns related view, or 0 if no view is related.
|
boolean |
isLocalized()
Checks if there's a i18n message.
|
String |
toString()
Provides string representation of the exception.
|
addSuppressed, fillInStackTrace, getCause, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace
public StructureException(@Nullable StructureError error)
error
- structure error codepublic StructureException(@Nullable StructureError error, @Nullable String message)
error
- structure error codemessage
- additional message textpublic StructureException(@Nullable StructureError error, @Nullable Long structure)
error
- structure error codestructure
- structure in questionpublic StructureException(@Nullable StructureError error, @Nullable Long structure, @Nullable Long row)
error
- structure error codestructure
- structure in questionrow
- related row IDpublic StructureException(@Nullable StructureError error, @Nullable Long structure, @Nullable Long row, @Nullable String message)
error
- structure error codestructure
- structure in questionrow
- related row IDmessage
- additional message textpublic StructureException(@Nullable StructureError error, @Nullable Long structure, @Nullable Long row, @Nullable String message, @Nullable Throwable cause)
error
- structure error codestructure
- structure in questionrow
- related row IDmessage
- additional message textcause
- throwable causepublic StructureException(@Nullable StructureError error, @Nullable Long structure, @Nullable Long row, @Nullable Long view)
error
- structure error codestructure
- structure in questionrow
- related row IDview
- related view IDpublic StructureException(@Nullable StructureError error, @Nullable Long structure, @Nullable Long row, @Nullable Long view, @Nullable String message)
error
- structure error codestructure
- structure in questionrow
- related row IDview
- related view IDmessage
- additional message textprotected StructureException(StructureError error, @Nullable Throwable cause, @Nullable Long structure, @Nullable Long view, @Nullable Long row, @Nullable ItemIdentity item, @Nullable String message, @Nullable String messageKey, @Nullable Object... messageParameters)
error
- structure error codecause
- throwable causestructure
- related structure IDview
- related view IDrow
- related row IDitem
- related item IDmessage
- additional message textmessageKey
- i18n message textmessageParameters
- i18n message parameterspublic String toString()
@NotNull public StructureError getError()
StructureError
enum value@NotNull public String getProblemDetails()
Returns the part of Throwable.getMessage()
that corresponds to the original description of the problem.
Does not contain structure ID, error code, and related item information, so is more user-friendly than Throwable.getMessage()
in case when that information can be more suitably described by the caller.
Normally you shouldn't use this method, use getLocalizedMessage()
instead. You may want to use this method
if you don't need a potentially localized message, but still need a more user-friendly English message about the problem.
Throwable.getMessage()
would return.public long getStructure()
public long getView()
public long getRow()
@Nullable public ItemIdentity getItem()
public boolean isLocalized()
getLocalizedMessage()
@NotNull public String getLocalizedMessage()
getProblemDetails()
.getLocalizedMessage
in class Throwable
getLocalizedMessage(ApplicationUser)
@NotNull public String getLocalizedMessage(@Nullable ApplicationUser user)
getProblemDetails()
.user
- target usergetLocalizedMessage()
@NotNull public I18nText asI18nText()
Copyright © 2023 ALM Works. All Rights Reserved.