Zrobiłem prostą obsługę wyjątków i błędów. Teoretycznie wszystko działa ale nie rozumiem jednej rzeczy. Dlaczego gdy rzucam mError działa moja metoda (poprawnie) i jednocześnie set_exception_handler (jako drugi) dublując wykonanie całości

//wersja robocza.
Throw new mError($e, 'mysqli_connection');
namespace libs\core; use Exception; use ErrorException; Class mError extends Exception { function __construct($e, string $type = null, string $comments = null) { $this->file = $e->getFile(); $this->line = $e->getLine(); $this->type = $type; $this->comments = $comments; parent::__construct($e->getMessage(), $e->getCode()); $this->eHandler(); } function eHandler() { $message = 'Napotkano nieoczekiwany błąd aplikacji.'; $notice = 'Przepraszamy, ale nie możemy wyświetlić strony której poszukujesz. Prosimy spróbować ponownie za kilka minut.'; switch($this->type) { case 'not_found': http_response_code(404); $message = 'Strony nie znaleziono.'; $notice = 'Przepraszamy, ale strona którą chcesz zobaczyć nie istnieje.'; break; case 'mysqli_query': case 'mysqli_connection': $message = 'Brak połączenia z serwerem MySQL'; break; } $this -> eDisplay($message, $notice); } function eDisplay(string $message, string $notice) { echo '<!DOCTYPE html> <html lang="pl"> <head> <meta charset="utf-8"> <title>'.$message.'</title> <meta name="robots" content="noindex"> <style type="text/css"> body {font-family: sans-serif; font-size: 14px; margin: 40px;} fieldset {border: 1px solid #a4a4a4; padding: 10px; background-color: #f2f2f2; margin: 10px 0} legend {padding: 0 10px; font-weight: bold; } h1, h3 {font-weight: normal;} h3 {border-bottom: 1px solid #a4a4a4; padding-bottom: 20px;} ul {list-style: none; margin: 0; padding:0;} li {padding-bottom: 4px;} </style> </head> <body>'; '<li>Code: '.$this -> getCode().'</li>'. '<li>Message: '. $this -> getMessage()."</li>". '<li>Line: '. $this -> line."</li>". //'<li>'.$this -> comments.'</li>', '</ul>'; } } else { echo 'Spróbuj <a href="java script: window.location.reload()">odświeżyć stronę</a> lub wróć na <a href="/">stronę główna</a>.'; } } } set_exception_handler(function($exception) { // echo '<pre>'; // print_r($exception); // echo '</pre>'; // New mError($exception); }); throw new ErrorException($errstr, null, $errno, $errfile, $errline, null); });