2

DECLARE EXIT HANDLER FOR SQLEXCEPTION ROLLBACK is "supposed" to be used before a transaction, to explicitly set the value on failure.

However, the documentation states that this is more or less the default behavior anyway?

If a condition occurs for which no handler has been declared, the action taken depends on the condition class:

For SQLEXCEPTION conditions, the stored program terminates at the statement that raised the condition, as if there were an EXIT handler. If the program was called by another stored program, the calling program handles the condition using the handler selection rules applied to its own handlers.

But that means COMMIT is never called, so, same effect as having no handler.

I'm not sure how to interpret that. It sounds like the "obvious" thing to do is exit the stored program, but if a calling program has handlers telling to do otherwise - perhaps a DECLARE EXIT HANDLER FOR SQLEXCEPTION CONTINUE - it's not clear to me whether the inside stored program continues or not, or what the "handler selection rules" are in general.

If this (strange to me) interpretation is the case, then that means if hypothetically a stored program could assume it was never called by another stored program, the handler is extraneous, but it ensures consistent behavior

Community
  • 1
  • 1
djechlin
  • 59,258
  • 35
  • 162
  • 290
  • One can still commit after the procedure exits. – eggyal Sep 17 '13 at 18:45
  • An exception handler only fires if the stated error condition occurs, and the purpose is to handle the error and mask it from the caller being able to see it, so it's not clear what you are trying to accomplish. Can you provide some specifics? If this handler fires, the BEGIN/END block that the EXIT handler is in will exit, but it will exit "successfully" because you handled the exception. You need to throw another exception if you don't want the block (and possibly the proc) to exit gracefully after you catch the exception (if one occurs). – Michael - sqlbot Sep 17 '13 at 21:05

0 Answers0