SQL Server Error Functions
SQL Server Error Functions is a SQL function in the SQL Server Specific category. SQL Server CATCH block functions that provide detailed error context for debugging. The syntax is ERROR_NUMBER(), ERROR_MESSAGE(), ERROR_LINE(), ERROR_PROCEDURE(), ERROR_SEVERITY(), ERROR_STATE(). It accepts see syntax. It returns error detail. A typical example: BEGIN TRY SELECT 1/0; END TRY BEGIN CATCH SELECT ERROR_NUMBER() AS error_number, ERROR_MESSAGE() AS error_message, ERROR_SEVERITY() AS severity, ERROR_STATE() AS state, ERROR_LINE() AS error_line, ERROR_PROCEDURE() AS error_procedure; END CATCH; -- Returns: -- 8134 | Divide by zero error encountered. | 16 | 1 | 2 | NULL -- Log errors to table: INSERT INTO error_log (number, message, severity, line, time) VALUES (ERROR_NUMBER(), ERROR_MESSAGE(), ERROR_SEVERITY(), ERROR_LINE(), GETDATE()); A close relative is OUTPUT Clause, which sQL Server: returns values from DML statements (like PostgreSQL RETURNING). A close relative is STUFF(), which sQL Server: deletes a specified length of characters from a string and inserts another string at the start position.