This article demo TRY/CATCH, THROW(),RAISERROR() and ERROR functions.
The first statement will catch the error but it wont display the actually error message because it has been catch.
After we add the THROW, it will also display the actual error message
Msg 2627, Level 14, State 1, Line 18
Violation of PRIMARY KEY constraint 'PK__testThro__3214EC2789EB1AE6'. Cannot insert duplicate key in object 'dbo.testThrow'. The duplicate key value is (1).
THROW Custom error
We can also use throw to throw the custom error. If we use the throw the custom error, the severity level would always be 16.
RAISEERROR is used to raise the custom error message or use sp_addmessage into the sys,messages so it can be reused again.