18th February 2024 - 8 minutes read time
Let's say you had a class that you wanted to use, but there was some sort of error in creating the object. This might be that the wrong parameters were passed, or the third party service (eg. a database) wasn't available at the time of creation.
If this happens you'll obviously want to handle the error correctly, but the question is would you throw an exception in the constructor or handle the error condition elsewhere?
Note that this article will talk about PHP, but the same discussion applies to other languages that implement OOP principles.