Closed alcohol closed 7 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.
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.
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.