Translations:Developers/Object oriented programming in PHP/Exceptions/5/en

If you encounter an unexpected condition in your code that can't be handled in your method, then it's best to throw an exception and let the calling method (or up to the initial script) to care about this. The above one is a good example for this: It expects a product item but gets something that doesn't implement the product item interface. Thus, it doesn't know what can be done with this object and before calling a method of the object that doesn't exist (which would result in a fatal error), it throws an exception.