[ https://issues.apache.org/jira/browse/DERBY-4443?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13015456#comment-13015456 ]
Knut Anders Hatlen commented on DERBY-4443: ------------------------------------------- > I guess I'm not quite sure I understand what rule StandardException is > enforcing. Is it OK for a StandardException to wrap a StandardException, but > if a SQLException wraps a StandardException than it gets automatically > unwrapped? It typically only gets unwrapped if it has been thrown inside a stored procedure (only exceptions generated by PublicAPI.wrapStandardException() are marked as "simple wrappers"). What it attempts to solve is the problem of passing exceptions through multiple layers. Inside the language layer and store, exceptions have to be passed as StandardExceptions, whereas in the JDBC layer they have to be passed as SQLExceptions. In the common case, an exception is generated inside the engine as a StandardException, and it gets wrapped in an SQLException on its way out through the JDBC layer. But in the case of stored procedures, the JDBC layer is reentered from the language layer. The exceptions that happen inside the stored procedure are returned to the language layer as SQLExceptions, but have to be transported as StandardExceptions through the language layer up to the outer JDBC layer. This could be done by wrapping the SQLException in a StandardException, but then the end result would be an SQLException wrapping a StandardException wrapping an SQLException wrapping a StandardException. By just passing the underlying StandardException, we save two layers of indirection. > Wrap rollback in exception handlers in try-catch > ------------------------------------------------ > > Key: DERBY-4443 > URL: https://issues.apache.org/jira/browse/DERBY-4443 > Project: Derby > Issue Type: Bug > Components: Demos/Scripts, Documentation, Eclipse Plug-in, JDBC, > Network Client, Network Server, Replication, Services, SQL, Test, Tools > Affects Versions: 10.5.3.0 > Reporter: Aaron Digulla > Assignee: Houx Zhang > Labels: derby_triage10_8 > Attachments: DERBY-4443-1.patch, DERBY-4443-2.patch, > DERBY-4443-3.patch, DERBY-4443-4.patch, DERBY-4443-4.png, DERBY-4443-5.patch, > DERBY-4443.patch > > > Avoid this pattern everywhere: > }catch(SQLException se){ > //issue a rollback on any errors > conn.rollback(); > throw se; > } > because an error in rollback will shadow the original exception. -- This message is automatically generated by JIRA. For more information on JIRA, see: http://www.atlassian.com/software/jira