I have views that handle different errors in my application. For example error 404, 403 and such, giving my errors a more user-friendly presentation. By assumption, they get passed in an exception, so this is what an example error-handling view looks like
<h1>Whooops! An error with code <?=$exception->getCode()?> has occurred.</h1>
<p><?=$exception->getMessage()?></p>
But somewhere along the lines I met a need to display a certain error view as only a part of a page, so I decided why not do this
// somewhere in another view
echo $errorView->render(new \Exception('Message', 403));
I wonder, in other languages like java exceptions are something that occur only if something really critical has happened, even though that is not the case with PHP, is it still OK to use exceptions so loosely?
Aucun commentaire:
Enregistrer un commentaire