Skip to content
Advertisement

Are all exceptions throw from Jdbi of type JdbiException?

It states here:

https://jdbi.org/apidocs/org/jdbi/v3/core/JdbiException.html

that JdbiException is the Base unchecked exception for exceptions thrown from jdbi.

However, if I’m calling the withHandle method with various different callbacks:

JavaScript

the docs state that it throws X extends Exception (rather than throwing JdbiExecption as I would have expected) and describes it as @param <X> exception type thrown by the callback, if any.:

JavaScript

I want to know if it is safe to do call withHandle and just catch JdbiException, rather than having to catch Exception?

JavaScript

Advertisement

Answer

The point of that X extends Exception is for your code, not JDBI’s code. The code you write yourself (after the ->) can throw X.

JDBI will indeed be throwing JdbiExceptions, and won’t be throwing anything else. But YOUR CODE might e.g. throw IOException or whatnot.

This works:

JavaScript

and to make that work, that’s what the <X extends Exception> is all about.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement