So I have this little bit of code
public function getPrices($debtorId)
{
$priceListId = $this->getPriceListId($debtorId);
if(!$priceListId){
throw new \Exception('No list found for this customer');
}
// doing some operations here that require $priceListId
return $prices;
Up until now, I would have done something like
if(!$priceListId) exit('No list found for this customer');
The difference being, that I could catch the Exception if I want to, while that's not possible with the exit statement.
However, in this case I do want my program to exit. But my IDE warns me that I'm not catching Exceptions. So, should I really do this now:
try {
$prices = $priceHandler->getPrices($debtorId);
} catch(Exception $e) {
exit($e->getMessage());
}
The latter appears to me as unecessary and actually decreasing code quality. So: Is it acceptable to deliberately NOT catch some exceptions? Or should I even get rid of the exception alltogether and just use plain old exit
?
I tried searching for this question, but I only got results about people who had technical problems with try/catch not working.