Translate

> > TSQL RaiseError from exception

TSQL RaiseError from exception

Posted on Sunday, January 24, 2021 | No Comments

 
ALTER PROCEDURE [dbo].[usp_GetErrorInfo]  
AS  

DECLARE @ErrorNumber INT
SET @ErrorNumber=ERROR_NUMBER()

DECLARE @ErrorSeverity INT
SET @ErrorSeverity=ERROR_SEVERITY()

DECLARE @ErrorState INT
SET @ErrorState=ERROR_STATE()

DECLARE @ErrorLine INT
SET @ErrorLine=ERROR_LINE()

DECLARE @ErrorMessage NVARCHAR(max)
SET @ErrorMessage=ERROR_MESSAGE()

--SELECT  
    
--    ERROR_NUMBER() AS ErrorNumber  
--    ,ERROR_SEVERITY() AS ErrorSeverity  
--    ,ERROR_STATE() AS ErrorState  
--    ,ERROR_PROCEDURE() AS ErrorProcedure  
--    ,ERROR_LINE() AS ErrorLine  
--    ,ERROR_MESSAGE() AS ErrorMessage;  


RAISERROR (@ErrorMessage, -- Message text.  
               @ErrorSeverity, -- Severity.  
               @ErrorState -- State.  
               ); 

Leave a Reply

Powered by Blogger.