SimonCropp/CountryData

Invalid country code throws System.Exception instead of more explicit ArgumentException or other.

RyanJMcGowan opened this issue · 1 comments

If a country code or state code is not valid, a ArgumentException or NotFoundException is more applicable. By throwing Exception, it's not possible to differentiate exceptions thrown by CountryData from other exceptions, making it impossible to properly handle exceptions from higher-level code.

Please change CountryLoader.cs Line 40 from:

throw new($"Could not find data for '{countryCode}'.");
to
throw new ArgumentException ($"Could not find data for '{countryCode}'.");

This should be a non-breaking change as ArgumentException still will be caught by code catching Exception.

sounds good. send me a pull request