title: PHP - Customise the Exception error
body: <p>I'm trying to customise the exception error with my custom error message as per below:</p>
  
  <pre><code>try {
          $test = 1/0;
      } 
      catch(Exception $ex){ 
          $t=time();
          $timelog = date("dmYhms",$t);
          error_log($timelog."=&gt; ErrorID: ".$timelog."\n", 3, "../error_log/Error.log");
          echo "System having issue with this request.\n
                  Transaction ID: ".$timelog; 
      } 
  </code></pre>
  
  <p>My expectation was, I managed to <code>echo</code> the custom message instead the default message and I managed to write in the log file. But, I'm still getting the default error message instead the custom one as per image below.
  <a href="https://i.stack.imgur.com/EykZw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EykZw.png" alt="enter image description here"></a></p>
  
  <p>Any idea where I did the mistake. Please advice. </p>
  
  <p><strong>EDITED</strong></p>
  
  <pre><code>error_reporting(0);
  //error handler function
  function customError($errno, $errstr) {
    //echo "&lt;b&gt;Error:&lt;/b&gt; [$errno] $errstr&lt;br&gt;";
      $t=time();
      $timelog = date("dmYhms",$t);
      echo "Unable to process with the request. \n Error ID".$timelog.". PLease contact RND team.";
      error_log($timelog."=&gt; Error: [$errno] $errstr\n", 3, "error_log/Error.log");
  }
  
  //set error handler
  set_error_handler("customError",E_USER_WARNING);
  
  //trigger error
  $username = "xxx";
  $password = "xxx";
  $host = "xxxx";
  $dbname = "xxx";
  
  $db = new mysqli($host, $username, $password,$dbname);
  if ($db-&gt;connect_error) {
      trigger_error($db-&gt;connect_error,E_USER_WARNING);
  }
  </code></pre>
  
  <p>The above edited sample working fine but, is this the best practice. Please advice.</p>