I can't seem to find anywhere how to catch and re-throw any errors or warnings that can occur in a procedure.
What I want is the syntax to do the following:
create procedure myProcedure()   begin        declare exit handler for ANYTHING_WRONG_THAT_CAN_BE_CAUGHT_WARNINGS_INCLUDED       begin           rollback;           RE_THROW THE_THING_THAT_WAS_CAUGHT;       end;        start transaction;          -- do some stuff       commit;   end; //   The reason being that I want to force a rollback on an error or warning but leave it up to the client to decide what to do with the specific error.
The all-cap areas are the portions where I do not know what to put.
Thanks for any help!
Edit -------
I have since learned it is not possible to do what I have asked :'(.
Instead I have a single error for anything that goes wrong and used the following code:
declare exit handler for sqlwarning, sqlexception begin     rollback;     call error(); end;   (error() does not exist)
You can try "\! clear" , it will execute clear shell command. "\!" is used to execute shell command. in *nix it will clear your command prompt.
The SHOW COUNT(*) ERRORS statement displays the number of errors. You can also retrieve this number from the error_count variable: SHOW COUNT(*) ERRORS; SELECT @@error_count; SHOW ERRORS and error_count apply only to errors, not warnings or notes.
If a condition whose value matches the condition_value , MySQL will execute the statement and continue or exit the current code block based on the action . The action accepts one of the following values: CONTINUE : the execution of the enclosing code block ( BEGIN … END ) continues.
To catch all SQL exceptions, use:
DECLARE EXIT HANDLER FOR SQLEXCEPTION   SQLWARNINGS can be used to catch warnings also.
Inside the exception handler, to raise the error or warning that was just caught, use:
RESIGNAL   See the documentation for the RESIGNAL statement:
http://dev.mysql.com/doc/refman/5.5/en/resignal.html
This is available since MySQL 5.5
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With