isValidPhoneNumber throws exception instead of returning false
When I passed "+1" to isValidPhoneNumber, it throws the following exception:
E/flutter (13120): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(NumberParseException, The string supplied did not seem to be a phone number., null)
isn't the point to return false when it's not a phone number?
I'm planning on adding a try catch block around this function, happy to submit a PR if approved, does that make sense?
Yes, you are right. This function should never throw an exception, but only return the boolean value.
If you could create a PR for it, I would appreciate it a lot!
Thanks! PR in https://github.com/emostar/flutter-libphonenumber/pull/18
Hi @emostar, there is a similar issue for PhoneNumberUtil.getRegionInfo and .normalizePhoneNumber when using an invalid phone number. Is this expected behaviour? Should we validate the phone number before trying to call these methods, or should it return a default value on PlatformException?
Yeah I think getRegionInfo and normalizePhoneNumber needs the number to be valid, so throwing an exception is proper. You can either call isValidPhoneNumber first or have a catch block yourself to handle the exception (e.g. present error message back to user).