Top Description Inners Fields Constructors Methods
org.apache.derby.shared.common.error

public Class StandardException

extends Exception
Class Inheritance
Imports
java.lang.reflect.InvocationTargetException, java.sql.SQLException, .SQLWarning, org.apache.derby.shared.common.error.ExceptionSeverity, org.apache.derby.shared.common.reference.SQLState, org.apache.derby.shared.common.util.ArrayUtil, org.apache.derby.shared.common.i18n.MessageService, org.apache.derby.shared.common.sanity.SanityManager

StandardException is the root of all exceptions that are handled in a standard fashion by the database code, mainly in the language code.

This class is abstract to ensure that an implementation only throws a specific exception (e.g. TransactionException) which is a sub-class

A method in an iterface in a protocol under com.ibm.db2j.protocol.Database must only throw a StandardException (if it needs to throw an exception). This indicates that the method can throw an exception and therefore its caller must ensure that any resources it allocates will be cleaned up in the event of an exception in the StandardException hierarchy.

Implementations of methods that throw StandardException can have throws clause that are more specific than StandardException.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
StandardException.BadMessageArgumentException

Dummy exception to catch incorrect use of StandardException.newException(), at compile-time.

Field Summary

Modifier and TypeField and Description
private transient Object[]
private transient boolean
private transient SQLException
private transient int
public static final int
public static final int
public static final int
private int
private String
private String

Constructor Summary

AccessConstructor and Description
protected
protected
StandardException(String messageID, Throwable t, Object[] args)

private
StandardException(String
the sql state of the message
sqlState
,
String
the text of the message
text
)

This constructor is used when we already have the message text.

Method Summary

Modifier and TypeMethod and Description
public static StandardException

Returns:

a "session close" exception
closeException
()

A special exception to close a session.

public static StandardException

Returns:

a Derby exception wrapping the contents of the SQLException
getArgumentFerry
(SQLException
A SQLException
se
)

Unpack the exception, looking for a StandardException, which carries the Derby messageID and arguments.

public final Object[]
public final int
public String

Returns:

the corresponding error code
getErrorProperty
(String
An error type
type
)

Get the error code for an error given a type.

private static String
getErrorProperty(String messageId, String type)

public String

Returns:

the message text
getMessage
()

Overrides java.lang.Throwable.getMessage.

The message stored in the super class Throwable must be set up object creation.

public final String

Returns:

the message id
getMessageId
()

Return the message identifier that is used to look up the error message text in the messages.properties file.

public final SQLException

Returns:

the next exception
getNextException
()

Get the next SQLException that should be put into the parent exception when this instance is converted to an SQLException.

public final int
public static int

Returns:

the severity associated with the message
getSeverityFromIdentifier
(String
The handle on the message
messageID
)

Get the severity given a message identifier from org.apache.derby.shared.common.reference.SQLState.

public final String

Returns:

the 5 character SQL state
getSQLState
()

Return the 5 character SQL State.

public static String

Returns:

String - the 5 character code of the SQLState ID to returned to the user
getSQLStateFromIdentifier
(String
- the sql state id of the message from Derby
messageID
)

Convert a message identifer from org.apache.derby.shared.common.reference.SQLState to a SQLState five character string.

public static StandardException
public final boolean

Returns:

true if this exception is a lock timeout.
isLockTimeout
()

Is this a lock timeout exception.

public final boolean

Returns:

true if this exception is a lock timeout or lock deadlock.
isLockTimeoutOrDeadlock
()

Is this a lock timeout or lock deadlock exception.

public final boolean

Returns:

true if this exception is a self-deadlock.
isSelfDeadlock
()

Is this a self-deadlock exception caused by a nested transaction being blocked by its parent's locks.

private static boolean

Returns:

true if the throwable is a vacuous wrapper and the only useful piece of information is the cause, or false otherwise
isVacuousWrapper
(Throwable
the throwable to check
t
)

Check if the top-level throwable is just a vacuous wrapper that does not carry any useful information except what's returned by the Throwable#getCause() method.

pack-priv final void
markAsPublicAPI()

Mark this exception as one that is thrown by a public API method.

public static StandardException
newException(String messageId, Object... args)

public static StandardException
newException(String messageId, Throwable t, Object... args)

public static StandardException

Returns:

nothing - always throws
newException
(String
- the sql state id of the message
messageID
,
Object
- Message arg
a1
,
Throwable
- Incorrectly placed exception to be nested
t
)

Dummy overload which should never be called.

public static StandardException

Returns:

nothing - always throws
newException
(String
- the sql state id of the message
messageID
,
Object
- First message arg
a1
,
Object
- Second message arg
a2
,
Throwable
- Incorrectly placed exception to be nested
t
)

Dummy overload which should never be called.

public static StandardException

Returns:

a Derby exception
newPreLocalizedException
(String
The SQLState and severity are derived from the ID. However the text message is not.
MessageID
,
Throwable
The Throwable that caused this exception, null if this exception was not caused by another Throwable.
t
,
String
The message associated with this exception. It is the caller's responsibility to ensure that this message is properly localized. See org.apache.derby.iapi.tools.i18n.LocalizedResource
localizedMessage
)

Creates a new StandardException using message text that has already been localized.

public static SQLWarning
newWarning(String messageId, Object... oa)

public static StandardException
public static StandardException

Returns:

a Derby exception which wraps the original error
plainWrapException
(Throwable
The original error which should be wrapped
t
)

Similar to unexpectedUserException but makes no assumtion about when the execption is being called.

public final int

Returns:

the report type
report
()

Yes, report me.

public final void
setReport(int
The report type
report
)

Set my report type.

public final void
setSeverity(int severity)

public String
toString()

Overrides java.lang.Throwable.toString.

Don't print the class name in the toString() method.
public static StandardException

Field Detail

argumentsback to summary
private transient Object[] arguments
isForPublicAPIback to summary
private transient boolean isForPublicAPI
nextback to summary
private transient SQLException next
reportback to summary
private transient int report
REPORT_ALWAYSback to summary
public static final int REPORT_ALWAYS
REPORT_DEFAULTback to summary
public static final int REPORT_DEFAULT
REPORT_NEVERback to summary
public static final int REPORT_NEVER
severityback to summary
private int severity
sqlStateback to summary
private String sqlState
textMessageback to summary
private String textMessage

Constructor Detail

StandardExceptionback to summary
protected StandardException(String messageID)
StandardExceptionback to summary
protected StandardException(String messageID, Throwable t, Object[] args)
StandardExceptionback to summary
private StandardException(String sqlState, String text)

This constructor is used when we already have the message text.

Parameters
sqlState:String

the sql state of the message

text:String

the text of the message

Method Detail

closeExceptionback to summary
public static StandardException closeException()

A special exception to close a session.

Returns:StandardException

a "session close" exception

getArgumentFerryback to summary
public static StandardException getArgumentFerry(SQLException se)

Unpack the exception, looking for a StandardException, which carries the Derby messageID and arguments. See org.apache.derby.impl.jdbc.SQLExceptionFactory See org.apache.derby.impl.jdbc.Util

Parameters
se:SQLException

A SQLException

Returns:StandardException

a Derby exception wrapping the contents of the SQLException

getArgumentsback to summary
public final Object[] getArguments()
getErrorCodeback to summary
public final int getErrorCode()
getErrorPropertyback to summary
public String getErrorProperty(String type)

Get the error code for an error given a type. The value of the property messageId.type will be returned, e.g. deadlock.sqlstate.

Parameters
type:String

An error type

Returns:String

the corresponding error code

getErrorPropertyback to summary
private static String getErrorProperty(String messageId, String type)
getMessageback to summary
public String getMessage()

Overrides java.lang.Throwable.getMessage.

The message stored in the super class Throwable must be set up object creation. At this time we cannot get any information about the object itself (ie. this) in order to determine the natural language message. Ie. we need to class of the objec in order to look up its message, but we can't get the class of the exception before calling the super class message.

Thus the message stored by Throwable and obtained by the getMessage() of Throwable (ie. super.getMessage() in this class) is the message identifier. The actual text message is stored in this class at the first request.

Returns:String

the message text

getMessageIdback to summary
public final String getMessageId()

Return the message identifier that is used to look up the error message text in the messages.properties file.

Returns:String

the message id

getNextExceptionback to summary
public final SQLException getNextException()

Get the next SQLException that should be put into the parent exception when this instance is converted to an SQLException.

Returns:SQLException

the next exception

getSeverityback to summary
public final int getSeverity()
getSeverityFromIdentifierback to summary
public static int getSeverityFromIdentifier(String messageID)

Get the severity given a message identifier from org.apache.derby.shared.common.reference.SQLState.

Parameters
messageID:String

The handle on the message

Returns:int

the severity associated with the message

getSQLStateback to summary
public final String getSQLState()

Return the 5 character SQL State. If you need teh identifier that was used to create the message, then use getMessageId(). getMessageId() will return the string that corresponds to the field in org.apache.derby.shared.common.reference.SQLState.

Returns:String

the 5 character SQL state

getSQLStateFromIdentifierback to summary
public static String getSQLStateFromIdentifier(String messageID)

Convert a message identifer from org.apache.derby.shared.common.reference.SQLState to a SQLState five character string.

Parameters
messageID:String

- the sql state id of the message from Derby

Returns:String

String - the 5 character code of the SQLState ID to returned to the user

interruptback to summary
public static StandardException interrupt(InterruptedException ie)
isLockTimeoutback to summary
public final boolean isLockTimeout()

Is this a lock timeout exception.

Returns:boolean

true if this exception is a lock timeout.

isLockTimeoutOrDeadlockback to summary
public final boolean isLockTimeoutOrDeadlock()

Is this a lock timeout or lock deadlock exception.

Returns:boolean

true if this exception is a lock timeout or lock deadlock.

isSelfDeadlockback to summary
public final boolean isSelfDeadlock()

Is this a self-deadlock exception caused by a nested transaction being blocked by its parent's locks.

Returns:boolean

true if this exception is a self-deadlock.

isVacuousWrapperback to summary
private static boolean isVacuousWrapper(Throwable t)

Check if the top-level throwable is just a vacuous wrapper that does not carry any useful information except what's returned by the Throwable#getCause() method.

Parameters
t:Throwable

the throwable to check

Returns:boolean

true if the throwable is a vacuous wrapper and the only useful piece of information is the cause, or false otherwise

markAsPublicAPIback to summary
pack-priv final void markAsPublicAPI()

Mark this exception as one that is thrown by a public API method. The purpose is to signal that this should be a top-level exception, so that it doesn't get wrapped inside multiple layers of other SQLExceptions or StandardExceptions as it travels up through the code layers.

See Also
PublicAPI
newExceptionback to summary
public static StandardException newException(String messageId, Object... args)
newExceptionback to summary
public static StandardException newException(String messageId, Throwable t, Object... args)
newExceptionback to summary
public static StandardException newException(String messageID, Object a1, Throwable t) throws BadMessageArgumentException

Dummy overload which should never be called. Only used to detect incorrect usage, at compile time.

Parameters
messageID:String

- the sql state id of the message

a1:Object

- Message arg

t:Throwable

- Incorrectly placed exception to be nested

Returns:StandardException

nothing - always throws

Exceptions
BadMessageArgumentException:
- always (dummy)
newExceptionback to summary
public static StandardException newException(String messageID, Object a1, Object a2, Throwable t) throws BadMessageArgumentException

Dummy overload which should never be called. Only used to detect incorrect usage, at compile time.

Parameters
messageID:String

- the sql state id of the message

a1:Object

- First message arg

a2:Object

- Second message arg

t:Throwable

- Incorrectly placed exception to be nested

Returns:StandardException

nothing - always throws

Exceptions
BadMessageArgumentException:
- always (dummy)
newPreLocalizedExceptionback to summary
public static StandardException newPreLocalizedException(String MessageID, Throwable t, String localizedMessage)

Creates a new StandardException using message text that has already been localized.

Parameters
MessageID:String

The SQLState and severity are derived from the ID. However the text message is not.

t:Throwable

The Throwable that caused this exception, null if this exception was not caused by another Throwable.

localizedMessage:String

The message associated with this exception. It is the caller's responsibility to ensure that this message is properly localized. See org.apache.derby.iapi.tools.i18n.LocalizedResource

Returns:StandardException

a Derby exception

newWarningback to summary
public static SQLWarning newWarning(String messageId, Object... oa)
normalCloseback to summary
public static StandardException normalClose()
plainWrapExceptionback to summary
public static StandardException plainWrapException(Throwable t)

Similar to unexpectedUserException but makes no assumtion about when the execption is being called. The error is wrapped as simply as possible.

Parameters
t:Throwable

The original error which should be wrapped

Returns:StandardException

a Derby exception which wraps the original error

reportback to summary
public final int report()

Yes, report me. Errors that need this method to return false are in the minority.

Returns:int

the report type

setReportback to summary
public final void setReport(int report)

Set my report type.

Parameters
report:int

The report type

setSeverityback to summary
public final void setSeverity(int severity)
toStringback to summary
public String toString()

Overrides java.lang.Throwable.toString.

Don't print the class name in the toString() method.

Returns:String

Doc from java.lang.Throwable.toString.

a string representation of this throwable.

unexpectedUserExceptionback to summary
public static StandardException unexpectedUserException(Throwable t)
org.apache.derby.shared.common.error back to summary

public Class StandardException.BadMessageArgumentException

extends Throwable
Class Inheritance

Dummy exception to catch incorrect use of StandardException.newException(), at compile-time. If you get a compilation error because this exception isn't caught, it means that you are using StandardException.newException(...) incorrectly. The nested exception should always be the second argument.
See Also
StandardException#newException(String, Object, Throwable), StandardException#newException(String, Object, Object, Throwable)

Constructor Summary

AccessConstructor and Description
public

Method Summary

Inherited from java.lang.Throwable:
addSuppressedfillInStackTracegetCausegetLocalizedMessagegetMessagegetStackTracegetSuppressedinitCauseprintStackTraceprintStackTraceprintStackTracesetStackTracetoString

Constructor Detail

BadMessageArgumentExceptionback to summary
public BadMessageArgumentException()