SQL Server Interview Question #118
What is THROW and how is it used?
Views, Stored Procedures & User-Defined Functions Mid-Level Intermediate
Detailed Explanation
THROW raises an exception in T-SQL. Inside a CATCH block, THROW without arguments rethrows the current exception while preserving its error information.
THROW can also create a new error when supplied with an error number of 50000 or greater, a message, and a state. It is generally preferred for modern T-SQL error handling over older RAISERROR patterns when its capabilities meet the requirement.
Code Example
IF @Price < 0
BEGIN
THROW 50001, 'Price cannot be negative.', 1;
END;