Use of "Set $ECODE"
objectscriptQuality release
Id
OS0027
Rule type
Code Smell
Severity
Blocker
Blocker
SQALE characteristic
- Reliability
- Exception handling
Remediation function
Constant/issue
Remediation cost
1d
Setting the $ECODE special variable is especially confusing and, moreover, dangerous:
- it will throw an exception if and only if the value is not an empty string;
- since this is the SET command, in addition to this, there may also be a postconditional.
As a result, when reading this line:
set:someCondition $ecode = somevalue
it is impossible to tell whether the code will actually throw an exception, apart from having studied all the body of the method prior to this statement (to figure out the value of both the someCondition and somevalue variables).
Using THROW has none of these problems.