Even you wrap exit()
into a member function of an exception, you are not using the exception here for error handling, but just the exit()
- the exception is never thrown, PHP comes to halt before that happens.
So it works just fine, but is this bad practice/coding?
Yes, it is bad practice. It also works just fine if you would have created yourself a function:
function error_exit($message) {
exit("<h1 style='color:red;' >FATAL ERROR: $message </h1>");
}
Instead think about whether you want to use Excpetions or you want to exit()
.