How do you throw custom errors in SQL

We can use raiseError to throw custom exceptions in an P-SQL block.

Example:

RAISERROR (N'Error Raised: %s %d.', -- Message text.  
           10, -- Severity,  
           1, -- State,  
           N'number', -- First argument from the 
           5); -- Second argument.  

Returns Error Message: Error Raised: number 5.

SQL Posted Sep 20, 2020

You can now show your support. 😊

We use cookies to provide you with a great user experience, analyze traffic and serve targeted promotions.   Learn More   Accept