The following constructs are supported with the natively compiled store procedure.
- ERROR_MESSAGE() - returns the complete text of the error message
- ERROR_NUMBER() – Error number
- ERROR_LINE() - returns the error line number inside the routine
- ERROR_PROCEDURE()- returns the name of the procedure or the trigger in which the error occurred
- ERROR_SEVERITY() - returns the severity of the error
- ERROR_STATE() - returns the error state
CREATE PROCEDURETestProc_TRY_CATCH
( )
WITH NATIVE_COMPILATION, SCHEMABINDING,
EXECUTE ASOWNER
AS
BEGIN ATOMIC WITH
(
TRANSACTION ISOLATIONLEVEL = SNAPSHOT,
LANGUAGE = N'English'
)
BEGIN TRY
DECLARE @myInt AS INT = 'Error Test'
END TRY
BEGIN CATCH
SELECT
ERROR_SEVERITY() AS ErrorSeverity,
ERROR_STATE() AS ErrorState,
ERROR_PROCEDURE() AS ErrorProcedure,
ERROR_LINE() AS ErrorLine,
ERROR_MESSAGE() AS ErrorMessage
END CATCH
END

Join the conversation! Your thoughts help the community grow.