The THROW Statement in SQL Server 2014
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_iE52qFBi8f0UgT10lHfKxIRfCg8Utnmre2dC2Rq4yFcXrWC1zTeJHdB74PZTgYw6GUSQfSQaHJjOklzSz1TvTqLyq_b6GT1v7GC_kzrzETJRkiES4KsLsTDrz3xpiFHDMWdhrpaAU18/s320/Untitled.png)
The THROW statement includes parameters to define a user-defined error. Alternatively, in a
CATCH block you can use THROW without parameters to re-throw the original error.
This code sample shows how to use the THROW keyword to throw a custom exception.
Using the THROW statement
CREATE PROCEDURE GetCustomerDetails @CustomerKey int
AS
SELECT * FROM Customers WHERE CustomerKey = @CustomerKey
IF @@ROWCOUNT = 0
THROW 50001, ‘Customer does not exist’, 1
The THROW Statement in SQL Server 2014
Reviewed by Unknown
on
12:04 AM
Rating:
![The THROW Statement in SQL Server 2014](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_iE52qFBi8f0UgT10lHfKxIRfCg8Utnmre2dC2Rq4yFcXrWC1zTeJHdB74PZTgYw6GUSQfSQaHJjOklzSz1TvTqLyq_b6GT1v7GC_kzrzETJRkiES4KsLsTDrz3xpiFHDMWdhrpaAU18/s72-c/Untitled.png)
No comments: