rohd
rohd copied to clipboard
Make `LogicValue` `toInt`, `toBigInt`, etc. return `null` when signal is invalid instead of an Exception
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.
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.
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()
I will work on this.