Bug #13560 | EXIT HANDLER exits declaring block, not the block raising the condition | ||
---|---|---|---|
Submitted: | 28 Sep 2005 11:48 | Modified: | 21 Nov 2005 19:28 |
Reporter: | Roland Bouman | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: Documentation | Severity: | S3 (Non-critical) |
Version: | 5.0.x | OS: | |
Assigned to: | Paul DuBois | CPU Architecture: | Any |
[28 Sep 2005 11:48]
Roland Bouman
[28 Sep 2005 13:05]
Valeriy Kravchuk
Handlers are declared in the block. So, for them "current BEGIN END block" is the one in which they are declared. In your block with cursor there is no handler, so exception was propogated to the outer block. You can declare handler here as EXIT, then this block will be exited, or as CONTINUE, then execution will be continued. In the CONTINUE handler you can set some variable and check it in each you block before proceeding... So, current implementation is flexible enough. In other similar languages, like Oracle PL/SQL, "EXIT-behaviour" and exception propogation described above is also present and used by default. So, I do not think that it is a bug in server - it is the intended behaviour. But I agree, that documentation should be more detailed and include examples similar to yours.
[28 Sep 2005 14:44]
Roland Bouman
Thanks for your quick reply Valeriy, we seem to agree on most of this. I agree that the propagation model in MySQL matches the one used in Oracle PLSQL (which is fine). I also agree that by specifying an actual statement within the handler (instead of my void BEGIN..END), you could do useful work, and achieve whatever control you need. It's just that, to me, it seems the MySQL sp language wants a programmer to do quite a bit more work than necessary to write an ordinary loop to traverse a CURSOR. I stumbled upon the EXIT HANDLER thing in an attempt to write a generic handler that takes care of the, in my opinion, quite normal situation of an exhausted cursor. So, I gueas I'm saying I'd really like a FOR record IN cursor/subquery LOOP construct to take care of the opening, fetching and closing sequence you see when working with cursors. Anyway, thanks!
[21 Nov 2005 19:28]
Paul DuBois
Thank you for your bug report. This issue has been addressed in the documentation. The updated documentation will appear on our website shortly, and will be included in the next release of the relevant product(s). Additional info: The handler exits the block in which the handler is declared, even if the condition occurs in an inner block.