Home

CATCH clauses should do more than rethrow

Rule description

  • CATCH clauses should do more than rethrow

 

Non-compliant Code Example

BEGIN TRY  
    EXECUTE usp_ExampleProc;  
END TRY  
BEGIN CATCH  
   THROW; -- Non compliant code (In the catch block we simply throwing the exception)
END CATCH;

Compliant Code Example

BEGIN TRY  
    EXECUTE usp_ExampleProc;  
END TRY  
BEGIN CATCH  
    SELECT   --Compliant code (In the catch block we process the exception and throw)
        ERROR_NUMBER() AS ErrorNumber  
        ,ERROR_MESSAGE() AS ErrorMessage;  
    THROW;
END CATCH;
Visual Expert 2020
 VETSQLRULE50