Throw an error message with throw

Source: Internet
Author: User

The Throw command does not have the exception severity parameter, the exception severity is always set to 16.

Raises an exception and transfers execution to a CATCH block of a TRY ... CATCH construct in SQL Server 2012.

[  {error_number | @local_variable},        {message | @local_variable},        ][  ]

Arguments

Error_number

is a constant or variable that represents the exception. Error_number is int and must are greater than or equal to 50000 and less than or equal to 2147483647.

message

is a string or variable that describes the exception. message is nvarchar (2048).

State

is a constant or variable between 0 and 255 that indicates the state to associate with the message. State is tinyint.

Remarks

If a TRY ... CATCH construct is not available and the session is ended. The line number and procedure where the exception was raised are set. The severity is set to.

If The THROW statement is specified without parameters, it must appear inside a CATCH block. This causes the caught exception to be raised. Any error This occurs in a THROW statement causes the statement batch to be ended.

State's role: if you raise the same user-defined error in more than one location, using a unique status number for each location helps you find the snippet that caused the error.

Examples

51000 ' The record does not exist. ' 1;

Reference Documentation:

THROW (Transact-SQL)

Throw an error message with throw

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.