Open utterances-bot opened 3 years ago
Really Nice blog, as an advice and I think it's a common php usage, don't put php end tags on pages '?>', this will prevent sending new lines and unwanted pieces of code of strings.
Also using you technique may prevent filtering Exceptions Types in try catch
try {
// piece of code
} catch(Exception | TypeError $e) {
echo 'Critical Failure';
} catch(IsUser $e) {
echo 'we can only filter on IsUser exception type';
}
see you cannot filter notAllowed
or toEmailNull
using your technique.
How ever this pattern is still sweet :)
Benefits of using custom exceptions in PHP – Amit Merchant – A blog on PHP, JavaScript and more
Exceptions are really useful when you want to handle some situations which can not be handled gracefully otherwise. So, using exceptions, you can handle certain sceanrios by showing a nice error message. Take the following example for instance.
https://www.amitmerchant.com/using-custom-exception-php/