alcohol / iso3166

A PHP library providing ISO 3166-1 data.
https://iso3166.thephpleague.com
MIT License
649 stars 60 forks source link

BC Break: use namespaced exceptions, not SPL ones (questionable?) #20

Closed alcohol closed 7 years ago

alcohol commented 8 years ago

Instead of using generic SPL exceptions, I think it would be better to use local namespace exceptions, specifically tailored for each use-case. This will make testing also easier/more robust. This change would not be backwards compatible however.

nyamsprod commented 8 years ago

Using SPL Exceptions is fine but I would agree that some exceptions your are throwing are strange. For Instance DataProvider::getAlpha2 only accept strings. So if I gave it an array I would expect an InvalidArgumentException to be thrown not a DomainException.

So re-arranging the exceptions thrown should be a good Idea :+1: . Adding more exception classes while the SPL Exception seem to cover all the library exceptions (AFAIK) seems strange to me.

alcohol commented 8 years ago

That is true to a certain extend. However, ambiguity arises if you let exceptions bubble up in your application. You cannot reliably assume that any DomainException or InvalidArgumentException was specifically thrown by this library or a specific method in this library. Whereas if the type of exception was more explicit and it was namespaced, you could.