Begin catch ... End catch is used to handle exceptions.
BeginTry
--SQL
EndTry
BeginCatch--SQL (handling Error actions)
EndCatch
We'll probably write the error SQL at begin try ...EndTry, if there is an error, just the program jumps to the immediately following begin try ...EndBeign Catch of Try ...EndCatch
, execute beign catch ...EndCatch error handling SQL. Try: Catch can be nested.
At Begin catch ...EndIn catch we can use the following four functions provided by the system to get the error message:
Error_number return error code
Error_serverity returns the severity level of the error
Error_state Return Error status code
Error_message returns the complete error message
The above four functions at the same begin catch ...EndA catch can be used more than once, and the value is constant.
Here is a simple little example.
BeginTry
Select2/0
EndTry
BeginCatch
SelectError_number ()Aserror_number,
Error_message () aserror_message,
Error_state () aserror_ State,
Error_severity () aserror_severity
endcatch
Result:
-----
error_number error_message error_state error_severity
8134 encountered a divisor error with zero. 116
Begin catch in SQL ... Use of end catch