New answers tagged


Throw an exception when your code can't proceed the happy path without some information, or prerequisites. For example, in a hypothetical method makeSale(int $userId) you would throw an exception if there is no matching record for the given ID. You can't return a meaningful value or perform the required action, so you need to throw. If the ID comes from user ...

Top 50 recent answers are included