MySQL exception handler access exception being handled
I'm trying to rollback on an error, but still let the client receive the
error. This might actually be impossible, unless there is a way to access
the error in an exception handler.
It's possible to "throw" from an exception, i.e. it's possible to raise a
signal:
CREATE PROCEDURE p ()
BEGIN
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
SIGNAL SQLSTATE VALUE '99999'
SET MESSAGE_TEXT = 'An error occurred';
END;
DROP TABLE no_such_table;
END;
But this sample code from the MySQL doc looks horrible, because it
literally swallows all errors and jams them into one.
SHOW ERRORS seems relevant, but I don't see any way to work with it
programmatically, e.g. SELECT Code FROM (SHOW ERRORS); is not possible.
Is this possible? Is there a better practice that I'm missing entirely?
No comments:
Post a Comment