ERROR_NUMBER
reads error state
What changes
- Input
- the error that activated the current CATCH block
- Output or change
- error attribute (NULL outside CATCH)
- Return type
- int
Syntax at a glance
ERROR_NUMBER ( )
Work example
Branch on a known SQL Server error number inside a CATCH block.
Handle only errors with a documented recovery path and rethrow unexpected failures.
Check your work ERROR_NUMBER returns null outside CATCH and nested handlers can report different error scopes.
Practice SQL
Open in SQL FlowBEGIN TRY
SELECT 1 / 0;
END TRY
BEGIN CATCH
SELECT ERROR_NUMBER() AS error_number;
END CATCH;
Open Microsoft Learn for full syntax, permissions, and details for your version.