A T-SQL statement for raising an error at severity 16; used on its own inside a CATCH block, it re-raises the error that was caught. Whatever statement comes before it needs a terminating semicolon.
Read more: Microsoft Learn
In the Ultra Transcenders books
Each book explains THROW in context, with comparison tables and the common traps.
Terms in this definition
- T-SQL
The dialect of SQL that Microsoft uses for Azure SQL and SQL Server. Azure Monitor logs are queried with KQL instead.
Related terms
- FORMATMESSAGE
Builds message text in T-SQL from either a sys.messages entry or a string with printf-style markers like %d and %s. Because THROW can't substitute values on its own, the two are often used together.
- RAISERROR
A legacy way to signal an error in T-SQL, with a chosen severity and printf-style placeholders; severities from 19 upwards also need WITH LOG and either sysadmin or ALTER TRACE. Microsoft advises THROW for anything new.
- Stream-stream join
When Structured Streaming joins one stream to another, Spark keeps each side's rows in state while it waits for matching rows to appear. Adding watermarks and a range condition on event time lets Spark throw away stale rows, and these are mandatory for outer joins.
- TRY...CATCH
Error handling in T-SQL: when something fails inside
TRY, execution jumps toCATCH, whereERROR_NUMBER(),XACT_STATE()andTHROWcan deal with it. Compile errors and anything of severity 10 or below slip past.