Click or drag to resize

SA0144 : The code following the RETURN or the RAISERROR statements will never be executed

The topic describes the SA0144 analysis rule.

Message

The code following the RETURN or the RAISERROR statements will never be executed

Description

The rule checks T-SQL script and reports for dead code which will never be executed.

The rule checks stored procedures, functions and triggers for unreachable code following unconditional RETURN statement, after RAISERROR with severity > 10 or after RAISERROR inside BEGIN/END TRY block.

To fix the rule violation, review your code and remove the dead code.

SQL
 1CREATE PROCEDURE [dbo].[test_DeadCode_Rule]
 2(
 3    @Value1 BIGINT
 4) 
 5AS 
 6
 7IF (@Value1 = 0)
 8BEGIN
 9   RETURN 0
10END
11ELSE
12BEGIN
13    RETURN @Value1 + 1
14END
15
16RETURN -1;
17
18PRINT 'This message will never be printed'

Scope

The rule has a Batch scope and is applied only on the SQL script.

Parameters
NameDescriptionDefault Value
RuleSuppressMark

Suppress rule reporting a rule violation in case a comment containing the value of this parameter is found next to the source of violation.

IGNORE:SA0144

Remarks

The rule does not need Analysis Context or SQL Connection.

Categories

Design Rules

Additional Information
Example Test Script
SQL
 1ALTER PROCEDURE [dbo].[test_DeadCode_Rule]
 2(
 3@Param1 INT = 0
 4) 
 5AS 
 6BEGIN
 7
 8        BEGIN TRY
 9                RAISERROR('@Param1 should not be null',11, 111);
10                PRINT 'dead code'
11        END TRY
12        BEGIN CATCH 
13                SET @Param1 = 1
14        END CATCH 
15
16        IF (@Param1 > 0)
17        BEGIN
18                RETURN 100/@Param1;
19                PRINT 'This statement will not be executed';
20        END
21        IF (@Param1 < 0)
22        BEGIN
23                RAISERROR ('Raise error instead of using RETURN statement.', 2,1);
24                PRINT 'This statement will not be executed';
25        END
26END

Analysis Results

 MessageLineColumn
1SA0144 : The code following the RAISERROR statement will never be executed.92
2SA0144 : The code following the RETURN statement will never be executed.182
See Also

Other Resources