Skip to content

Cast to number of try catch block (TryNumber)

Type Scope Severity Activated
by default
Minutes
to fix
Tags
Code smell BSL
OS
Major Yes 2 standard

Description

It is incorrect to use exceptions to cast a value to a type. For such operations, it is necessary to use the capabilities of the TypeDescription object.

Examples

Incorrect:

Try
 NumberDaysAllowance = Number(Value);
Raise
 NumberDaysAllowance = 0; // default value
EndTry;

Correct:

TypeDescription = New TypeDescription("Number");
NumberDaysAllowance = TypeDescription.CastValue(Value);

Sources

Snippets

Diagnostic ignorance in code

// BSLLS:TryNumber-off
// BSLLS:TryNumber-on

Parameter for config

"TryNumber": false