Proper handling of database-related exceptions
by Dejan Bosanac
Some OR mapping frameworks tend to use batch update operations when dealing with the database. The "problem" that this approach introduces is that if any problem occurs during the update, a
java.sql.BatchUpdateExceptionexception will be thrown instead of the regular
java.sql.SQLException. If we don't handle
BatchUpdateExceptionproperly the message it will give us will not be very useful.
|It's interesting that you use 'logger.info(exception);' to log the exception, and then explicitly loop over the causes. Is this an explicit design choice, over 'logger.info(message, exception)' ? (the latter prints the stacktrace including the cause)|
People use various logging APIs so I wanted to show the most generic solution here. It serves demonstration purposes only.
You can get the same functionality by using the Commons Lang class/method ExceptionUtils.getFullStackTrace(Throwable t).