org.h2.message
Class DbException

java.lang.Object
  extended by java.lang.Throwable
      extended by java.lang.Exception
          extended by java.lang.RuntimeException
              extended by org.h2.message.DbException
All Implemented Interfaces:
java.io.Serializable

public class DbException
extends java.lang.RuntimeException

This exception wraps a checked exception. It is used in methods where checked exceptions are not supported, for example in a Comparator.

See Also:
Serialized Form

Method Summary
 DbException addSQL(java.lang.String sql)
          Set the SQL statement of the given exception.
static DbException convert(java.lang.Throwable e)
          Convert a throwable to an SQL exception using the default mapping.
static DbException convertInvocation(java.lang.reflect.InvocationTargetException te, java.lang.String message)
          Convert an InvocationTarget exception to a database exception.
static DbException convertIOException(java.io.IOException e, java.lang.String message)
          Convert an IO exception to a database exception.
static java.io.IOException convertToIOException(java.lang.Throwable e)
          Convert an exception to an IO exception.
static DbException get(int errorCode)
          Create a database exception for a specific error code.
static DbException get(int errorCode, java.lang.String... params)
          Create a database exception for a specific error code.
static DbException get(int errorCode, java.lang.String p1)
          Create a database exception for a specific error code.
static DbException get(int errorCode, java.lang.Throwable cause, java.lang.String... params)
          Create a database exception for a specific error code.
 int getErrorCode()
          Get the error code.
static DbException getInvalidValueException(java.lang.String value, java.lang.String param)
          Gets a SQL exception meaning this value is invalid.
 java.sql.SQLException getSQLException()
          Get the SQLException object.
static DbException getSyntaxError(java.lang.String sql, int index)
          Create a syntax error exception.
static DbException getSyntaxError(java.lang.String sql, int index, java.lang.String expected)
          Create a syntax error exception.
static DbException getUnsupportedException(java.lang.String message)
          Gets a SQL exception meaning this feature is not supported.
static java.lang.RuntimeException throwInternalError()
          Throw an internal error.
static java.lang.RuntimeException throwInternalError(java.lang.String s)
          Throw an internal error.
static java.sql.SQLException toSQLException(java.lang.Exception e)
          Convert an exception to a SQL exception using the default mapping.
 
Methods inherited from class java.lang.Throwable
fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getSQLException

public java.sql.SQLException getSQLException()
Get the SQLException object.

Returns:
the exception

getErrorCode

public int getErrorCode()
Get the error code.

Returns:
the error code

addSQL

public DbException addSQL(java.lang.String sql)
Set the SQL statement of the given exception. This method may create a new object.

Parameters:
sql - the SQL statement
Returns:
the exception

get

public static DbException get(int errorCode)
Create a database exception for a specific error code.

Parameters:
errorCode - the error code
Returns:
the exception

get

public static DbException get(int errorCode,
                              java.lang.String p1)
Create a database exception for a specific error code.

Parameters:
errorCode - the error code
p1 - the first parameter of the message
Returns:
the exception

get

public static DbException get(int errorCode,
                              java.lang.Throwable cause,
                              java.lang.String... params)
Create a database exception for a specific error code.

Parameters:
errorCode - the error code
cause - the cause of the exception
params - the list of parameters of the message
Returns:
the exception

get

public static DbException get(int errorCode,
                              java.lang.String... params)
Create a database exception for a specific error code.

Parameters:
errorCode - the error code
params - the list of parameters of the message
Returns:
the exception

getSyntaxError

public static DbException getSyntaxError(java.lang.String sql,
                                         int index)
Create a syntax error exception.

Parameters:
sql - the SQL statement
index - the position of the error in the SQL statement
Returns:
the exception

getSyntaxError

public static DbException getSyntaxError(java.lang.String sql,
                                         int index,
                                         java.lang.String expected)
Create a syntax error exception.

Parameters:
sql - the SQL statement
index - the position of the error in the SQL statement
expected - the expected keyword at the given position
Returns:
the exception

getUnsupportedException

public static DbException getUnsupportedException(java.lang.String message)
Gets a SQL exception meaning this feature is not supported.

Parameters:
message - what exactly is not supported
Returns:
the exception

getInvalidValueException

public static DbException getInvalidValueException(java.lang.String value,
                                                   java.lang.String param)
Gets a SQL exception meaning this value is invalid.

Parameters:
value - the value passed
param - the name of the parameter
Returns:
the IllegalArgumentException object

throwInternalError

public static java.lang.RuntimeException throwInternalError(java.lang.String s)
Throw an internal error. This method seems to return an exception object, so that it can be used instead of 'return', but in fact it always throws the exception.

Parameters:
s - the message
Returns:
the RuntimeException object
Throws:
java.lang.RuntimeException - the exception

throwInternalError

public static java.lang.RuntimeException throwInternalError()
Throw an internal error. This method seems to return an exception object, so that it can be used instead of 'return', but in fact it always throws the exception.

Returns:
the RuntimeException object

toSQLException

public static java.sql.SQLException toSQLException(java.lang.Exception e)
Convert an exception to a SQL exception using the default mapping.

Parameters:
e - the root cause
Returns:
the SQL exception object

convert

public static DbException convert(java.lang.Throwable e)
Convert a throwable to an SQL exception using the default mapping. All errors except the following are re-thrown: StackOverflowError, LinkageError.

Parameters:
e - the root cause
Returns:
the exception object

convertInvocation

public static DbException convertInvocation(java.lang.reflect.InvocationTargetException te,
                                            java.lang.String message)
Convert an InvocationTarget exception to a database exception.

Parameters:
te - the root cause
message - the added message or null
Returns:
the database exception object

convertIOException

public static DbException convertIOException(java.io.IOException e,
                                             java.lang.String message)
Convert an IO exception to a database exception.

Parameters:
e - the root cause
message - the message or null
Returns:
the database exception object

convertToIOException

public static java.io.IOException convertToIOException(java.lang.Throwable e)
Convert an exception to an IO exception.

Parameters:
e - the root cause
Returns:
the IO exception