Login
tryStatemets rule
Login

Trystatements rule

The rule to check do try statements in the code contains or not some expressions. Checked things:

The syntax in a configuration file is:

[ruleType] ?not? trystatements [checkType] [exceptionName]

Disabling the rule

It is possible to disable the rule for a selected part of the checked code by using pragma ruleOff: "tryStatements" in the code before it. For example, if the rule should be disabled for the selected statement, the full declaration of it should be:

{.ruleOff: "tryStatements".}
try:
  someProcedure()
except:
  discard

To enable the rule again, the pragma ruleOn: "tryStatements" should be added in the code before it. For example, if the rule should be re-enabled for the statement, the full declaration should be:

{.ruleOn: "tryStatements".}
try:
  someProcedure()
except IOError:
  discard

Examples

  1. Check if all try statements don't have defined exceptions to catch::

    check tryStatements empty

  2. Remove all occurences of Exception exception from try statements::

    fix not tryStatements name Exception