Return a custom error message in SQL Server
How to return a custom error message from SQL Server in case of error?
To return custom error message in case of error, we pass necessary parameter to the THROW
statement.
--- SELECT 'ITFunda'/0
BEGIN TRY
SELECT 'ITFunda'/0
END TRY
BEGIN CATCH
THROW 50001, 'Always use integer to divide by', 1
END CATCH
Throw has three parameters,
- ErrorNumber – must be greater than 50000 and less than 2147483647
- ErrorMessage – the error message to throw
- State – generally in between 0 to 255, to associate the state of the error message.

Views: 11667 | Post Order: 99