Begin catch in SQL ... Use of End catch

Source: Internet
Author: User
Tags error status code

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.