I'm thinking about porting a database from Sql Server 2005 to MySQL.
I've become accustomed to using SQL Server's TRY/CATCH block in stored procedures.
Does MySQL have something similar, or am I going to be forced to go back to the old-school "check the error return after every statement, and issue a goto if it failed" style of programming?
SQL Server TRY CATCH overviewIf the statements between the TRY block complete without an error, the statements between the CATCH block will not execute. However, if any statement inside the TRY block causes an exception, the control transfers to the statements in the CATCH block.
A TRY... CATCH construct catches all execution errors that have a severity higher than 10 that do not close the database connection. A TRY block must be immediately followed by an associated CATCH block. Including any other statements between the END TRY and BEGIN CATCH statements generates a syntax error.
A block consists of various types of declarations (e.g., variables, cursors, handlers) and program code (e.g., assignments, conditional statements, loops). The order in which these can occur is as follows: Variable and condition declarations.
A TRY… CATCH construct cannot span multiple blocks of Transact-SQL statements.
You can declare handlers for specific error results.
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