dart-validate
dart-validate copied to clipboard
Do not throw ArgumentError
As specified in the dart lang guide, we should not catch Argument Error exceptions.
When an object of that type or one of its subinterfaces like ArgumentError is thrown, it means there is a bug in your code. When your API wants to report to a caller that it is being used incorrectly throwing an Error sends that signal clearly.
Conversely, if the exception is some kind of runtime failure that doesn’t indicate a bug in the code, then throwing an Error is misleading. Instead, throw one of the core Exception classes or some other type.
Since this lib is most used to validade user input, and we probably want to catch the exception, instead of a code bug, it should throw an exception instead of an error.
I argue it should return a boolean instead.
Imagine if ''.isEmpty threw an exception!