Issue Details (XML | Word | Printable)

Key: DBUTILS-4
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Stefan Fleiter
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Commons DbUtils

[dbutils] ResultSetIterator should rethrow SQLExceptions as RuntimException

Created: 09/Nov/04 05:26 AM   Updated: 02/Jan/08 07:29 AM
Return to search
Component/s: None
Affects Version/s: Nightly Builds
Fix Version/s: 1.1

Time Tracking:
Not Specified

File Attachments:
  Size
Text File SQLRuntimeException.patch 2004-11-29 07:58 AM Stefan Fleiter 4 kB
Text File SQLRuntimeException_2.patch 2005-02-14 02:48 AM Stefan Fleiter 2 kB
Environment:
Operating System: other
Platform: Other

Bugzilla Id: 32120


 Description  « Hide
SQLExceptions are not handled.
See TODOs in org.apache.commons.dbutils.ResultSetIterator.java

From discussion in COM-1333
I do not think that swallowing the exception would be a good decission, the user
(of DbUtils) should know something went wrong and we should not hide application
bugs and make debugging more difficult.

I would implement this myself if nobody objects.



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Stefan Fleiter added a comment - 29/Nov/04 07:58 AM
Created an attachment (id=13575)
Patch for rethrowing SQLException as SQLRuntimeException in
ResultSetIterator.java

Three things which are controversial:

1. A subpackage named exceptions for only one class
Maybe there will be other exceptions, this solution
is ready for future enhancements.
2. Implementation of all exception constructors, but only one is used
Completeness.
3. Having no unittest for this
I have no time for adding one at the moment and I do not think
think it is really needed.

Please tell me what you think of this.


David Graham added a comment - 29/Nov/04 09:32 AM
Why not just wrap them in RuntimeException and add a note to the javadoc?
Adding an exception class plus a package seems like overkill.

Stefan Fleiter added a comment - 01/Dec/04 06:26 AM
The reason for this is that one may need to distinguish the Exception from other
RuntimeExceptions thrown by ones try-Block.

Now you can wrap your code with something like this (beware: not tested!):
try {
while (iter.hasNext()) { // do something }
} catch (SQLRuntimeException e) {
SQLException org = (SQLException) e.getCause();
throw new SQLException(org.getMessage(), org.getSQLState(),
org.getErrorCode());
}

It's the same reason we do not only distinguish between Exception and
RuntimeException but have subclasses like IllegalArgumentException.

Where is the problem with having another class, what does it cost?


Stefan Fleiter added a comment - 14/Feb/05 02:48 AM
Created an attachment (id=14272)
Rethrow SQLException as plain RuntimeException

This patch does what was asked for in comment 2.
Could this be applied?


David Graham added a comment - 14/Feb/05 03:52 AM
This may break current users of the iterator whether we throw a RuntimeException
or a subclass of it. I'm hesitant to break backwards compatibility but
supressing the exceptions makes the iterator rather useless anyways.

Stefan Fleiter added a comment - 18/Feb/05 06:22 AM
IMHO alls current uses of ResultSetIterator are broken because one can not
reliably know whether an exception has happend and data in a traversal of an
resultset is incomplete or not.
Better fix this now than never.

David Graham added a comment - 20/Feb/05 05:49 AM
I added a protected rethrow(SQLException) method that throws a RuntimeException.
We can't wrap the SQLException because our minimum Java level is 1.3. You can
subclass and override rethrow() to throw any exception you like. This should be
in the next nightly build.

Stefan Fleiter added a comment - 21/Feb/05 03:57 AM
Making the type of Exception overrideable by implementing a protected rethrow
method is simple an ingenious at the same time.
Thanks a lot.

Henri Yandell made changes - 16/May/06 09:47 AM
Field Original Value New Value
issue.field.bugzillaimportkey 32120 12341859
Henri Yandell made changes - 16/May/06 11:29 AM
Component/s DbUtils [ 12311110 ]
Key COM-1707 DBUTILS-4
Assignee Jakarta Commons Developers Mailing List [ commons-dev@jakarta.apache.org ]
Project Commons [ 12310458 ] Commons DbUtils [ 12310470 ]
Affects Version/s Nightly Builds [ 12311648 ]
Henri Yandell made changes - 16/May/06 12:18 PM
Affects Version/s Nightly Builds [ 12311745 ]
Henri Yandell made changes - 06/Jul/06 11:36 AM
Fix Version/s 1.1 [ 12311973 ]
Henri Yandell made changes - 02/Jan/08 07:29 AM
Status Resolved [ 5 ] Closed [ 6 ]