rohd icon indicating copy to clipboard operation
rohd copied to clipboard

Make `LogicValue` `toInt`, `toBigInt`, etc. return `null` when signal is invalid instead of an Exception

Open mkorbel1 opened this issue 2 years ago • 3 comments

Motivation

Dealing with null is easier with Dart's null safety than an exception.

Desired solution

Functions that might not have a valid int/BigInt representation due to invalid signal values (x/z) should return int? and BigInt? instead of throwing an exception when it is invalid.

Alternatives considered

Leave as it is with exceptions thrown when invalid.

mkorbel1 avatar Jun 06 '22 18:06 mkorbel1

It's worth considering which is better a little further. It might be good to look at other Dart conventions for toX types of functions.

mkorbel1 avatar Oct 21 '22 18:10 mkorbel1

Instead of changing the behavior of the existing API, what if we add "try" versions like these: https://api.flutter.dev/flutter/dart-core/int/parse.html https://api.flutter.dev/flutter/dart-core/int/tryParse.html

For example, LogicValue.tryToInt()

mkorbel1 avatar Jan 31 '23 19:01 mkorbel1

I will work on this.

priya-t12 avatar Jan 31 '23 19:01 priya-t12