0

Im working on API in which I'm trying to add custom message when PHP script fails to run.

What I come up with was

   try {
      //some codes
   } catch (Exception $e){
       //something
   }

and

    set_error_handler("someFunction");
    function displayError() {
        echo "An error occurred bor";
    }

But What exactly I need is, an error handler lets say, when PHP is unable to run code because of runtime error, or syntax error, it should show specific message on the API. If possible?

Amitoj
  • 171
  • 2
  • 15
  • 1
    https://www.php.net/manual/en/function.set-error-handler and https://www.php.net/manual/en/function.set-exception-handler and any time one of those gets triggered it's a 500-level "server busted" message because those are the top-level, last-line-of-defense error handlers. Set try/catch blocks in your code for 400-level "client did bad thing" messages. – Sammitch May 19 '21 at 17:32
  • This is not really possible. And why would you ever have live code with a syntax error? – miken32 May 19 '21 at 17:54

0 Answers0