Open jimmyzzxhlh opened 4 years ago
Note that some scenarios may result in the more generic FluentJdbcException. Only the ones that are thrown due to SQLException will be FluentJdbcSqlException.
The exceptions should be handled in the way it suits your needs best, the lib is purposely not oppinionated on this. The only scenario when the exceptions - thrown by fluentjdbc or other code - alter the flow is transaction rollbacks.
If handling exception at each query - like in the example you provided - is necessary, do that. Or you can choose to let it propagate higher and deal with there. The checked exceptions are abstracted away for that reason - you can choose where to handle them.
On Sun, May 10, 2020, 1:48 AM Zhongxia Zhou notifications@github.com wrote:
Hi,
Is there any documentation in terms of how exceptions should be handled? If I understand it correctly SQLException is wrapped into FluentJdbcSqlException, so to catch an exception it would be something like:
DataSource dataSource = ... FluentJdbc fluentJdbc = new FluentJdbcBuilder() .connectionProvider(dataSource) .build(); String queryString = ... try { fluentJdbc.query().update(queryString).run(); } catch (FluentJdbcSqlException e) { ... }
I'm not using the error handler as it is possible that the exception needs to be re-thrown and there is no way to re-throw an exception in a lambda statement.
Thanks for making this library, it makes JDBC SQL queries a lot cleaner!
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/zsoltherpai/fluent-jdbc/issues/77, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAPPNRNLSALYX67RW62VZBDRQXTWTANCNFSM4M5AADFQ .
Thanks for the response! One caveat regarding to abstracting away checked exceptions, is that people may not be aware that they need to handle the exceptions appropriately, which leads me to think that that throwing one single checked SQL exception can be still desirable.
Hi,
Is there any documentation in terms of how exceptions should be handled? If I understand it correctly
SqlException
is wrapped intoFluentJdbcSqlException
, so to catch an exception it would be something like:I'm not using the error handler as it is possible that the exception needs to be re-thrown and there is no way to re-throw an exception in a lambda statement.
Thanks for making this library, it makes JDBC SQL queries a lot cleaner!