Try block is too long

objectscriptQuality release 
1.0.0
Id 
OS0042
Rule type 
Code Smell
Severity 

Major

Major
SQALE characteristic 
  • Changeability
    • Logic
Tags 
design, maintainability
Remediation function 
Constant/issue
Remediation cost 
2h

It is common to see code such as this:

    try {
        // very large block of code here
    } catch (e) {
        // handle exception
    }

This, however, is often a misdesign: in all the statements inside the try block, it frequently happens that only one or two actually throw an exception.

It is therefore advised, both for readability and understandability, to keep try blocks as small and self-contained as possible.

Parameters

NameDescriptionDefault value
nrStatementsInTryBlock
Maximum number of statements in a try block
10