Error Handling
System Errors | Custom Errors |
---|---|
it can be viewed in the | to add a custom error message to the |
they are generated by T-SQL custom code based on your code or business logic. |
message_id is of
integer
type and ranges from 50,001 to 2,147,483,647. severity is ofsmallint
type and ranges from 1 through 25.
Raising Error with RAISERROR
RAISERROR
RAISERROR
allows SQL server to generate an error that could be caught by the calling process.
Raising Error with THROW
THROW
@@ERROR
@@ERROR
@@ERROR
is a system variable that holds the error number of the last error occured.
Disadvantage
the value that @@ERROR holds resets as a new error gets generated.
When working with @@ERROR
, it is recommended to capture the error number in separate a variable as soon as error occurs.
TRY...CATCH
Last updated