ceving
ceving

Reputation: 23876

How to catch "Invalid hex digit"?

I have a program, in which a SQLException gets thrown:

java.sql.SQLException: Fail to convert to internal representation: Invalid hex digit

The error gets thrown in oracle.sql.RAW.hexString2Bytes, because the input data is invalid.

How can I catch this specific error without catching all other SQLExceptions?

Upvotes: 0

Views: 3371

Answers (3)

gaborsch
gaborsch

Reputation: 15758

You can process your Exception, check the condition if you want to handle or not. If not handled, you can throw the original Exception to outer catch blocks to process.

try {
    ... your code here ...
} catch (SqlException e) {
    if (e.getErrorCode() == ...) {
        ... do your exception handling
    } else {
        throw e;  // <-- re-throw the original Exception
    }
}

Upvotes: 1

Not a bug
Not a bug

Reputation: 4314

You can get it by two method.

One is SQLException#getErrorCode() which will return an int, vendor-specific exception code for the SQLException object, and compare the int ( I don't know the exception code for "Invalid hex digit", but may be you can get this with System.out.println() )

And other method is you can get exception message by Throwable#getMessage() and check the message string.

Further you can refer : Retrieving Exceptions

Upvotes: 1

peter.petrov
peter.petrov

Reputation: 39477

You cannot do this. Exceptions are caught in Java based on their type (SQLException in this case). But still, you can catch all SQLException objects, inspect the exception message, and thhen process only those exceptions you are interested in (those with the specified message).

Upvotes: 0

Related Questions