Search⌘ K

Raising and Throwing Errors

Explore how to intentionally raise errors in T SQL with RAISERROR and THROW clauses. Understand the recommended THROW syntax for error handling and learn to log errors effectively within stored procedures and functions using TRY CATCH blocks.

There are times when we know that our stored procedures or functions might generate an error. In these cases, we can raise custom errors that have readable messages.

The RAISERROR() function

We can intentionally raise an error in our query using the RAISERROR() function. It has this syntax:

RAISERROR([Message], [Severity], [State])
...