I am developing an error handling system for my application. I want to base it on exceptions, and I want to receive email notifications of all exceptions that I did not expect.
I was thinking about the class:
class My_Exception extends Exception {
private $sendErrorReport = true;
public function __destruct() {
if ($this->sendErrorReport) {
}
}
public function cancelErrorReport() {
$this->sendErrorReport = false;
}
}
And I want to do something like this:
try {
do_something_that_can_throw_exception();
catch (My_Exception $e) {
if ($e->getCode() == I_KNOW_WHAT_TO_DO ) {
react_to_exception();
$e->cancelErrorReport();
} else {
show_error_message($e->getMessage());
}
}
So basically, when an exception occurs and the system determines what to do, it does not bother me as a developer. But when there is something that the system cannot handle, then they notify me. I don't want to post code that notifies me in a catch clause, because I'm sure I will forget it somewhere ...
Can I be sure that the __destuct exception method will be called?
__destruct ?
?