Error Reporting

We'll start off with a quick overview of the tools at your disposal for reporting errors to Transact-SQL code and to client applications. Transact-SQL's error reporting tools are neither elegant nor full featured, but they can usually be made to do what you want.

RAISERROR

You report errors from stored procedures via return codes and the RAISERROR command. RAISERROR doesn't exit from the procedure, it simply returns the specified error message and sets the @@ERROR automatic variable. You can pass your own error message to RAISERROR to return, or you can reference a predefined error number/message combo in the sysmessages table. An error number is always returned by RAISERROR, regardless of whether you actually specify one. If ...

Get Guru's Guide to SQL Server™ Stored Procedures, XML, and HTML, The now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.