ballerina-platform / ballerina-lang

The Ballerina Programming Language
https://ballerina.io/
Apache License 2.0
3.68k stars 751 forks source link

[Bug]: decimal:fromString() panics #43377

Open MohamedSabthar opened 1 month ago

MohamedSabthar commented 1 month ago

Description

public function main() {
    error|decimal val = decimal:fromString("ENT 12 N 0000");
}

The above code panic instead of returning an error.

Getting:

error: {ballerina}DecimalExponentError {"message":"too many exponents found in decimal value 'ENT 12 N 0000'"}
        at ballerina.lang.decimal.0:fromString(decimal.bal:206)
           bytes:main(bytes.bal:3)

Steps to Reproduce

No response

Affected Version(s)

No response

OS, DB, other environment details and versions

No response

Related area

-> Runtime

Related issue(s) (optional)

No response

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response

SasinduDilshara commented 1 month ago

As a workaround you can use the

public function main() {
    error|decimal val = trap decimal:fromString("ENT 12 N 0000");
}