Skip to content

Latest commit

 

History

History
35 lines (25 loc) · 1.18 KB

IfElseIfEndsWithElse.md

File metadata and controls

35 lines (25 loc) · 1.18 KB

Else...The...ElseIf... statement should end with Else branch (IfElseIfEndsWithElse)

Description

The rule is applied whenever the conditional operator If Then ElseIf contains one or more blocks **ElseIf **. After block ElseIf must be followed by block Else.

The requirement to the final blockElse - it protective programming. Such constructions are resistant to possible changes and do not mask possible errors.

The construct Else must either take appropriate action or contain a suitable comment as to why no action is being taken.

Examples

Incorrect:

If TypeOf(InputParameter) = Type("Structure") Then
    Result = FillByStructure(InputParameter);
ElsIf TypeOf(InputParameter) = Type("Document.Ref.MajorDocument") Then
    Result = FillByDocument(InputParameter);
EndIf;

Correct:

If TypeOf(InputParameter) = Type("Structure") Then
    Result = FillByStructure(InputParameter);
ElsIf TypeOf(InputParameter) = Type("Document.Ref.MajorDocument") Then
    Result = FillByDocument(InputParameter);
Else
    Raise "Parameter of invalid type passed";
EndIf;