Can’t Capture PHP Native Errors?

Asked

Viewed 38 times

-2

I’m trying to treat the native mistakes of PHP in case something goes unnoticed, the error is treated and show a message in a more user-friendly way, but even using the Throwable in the try catch, it just bursts the error and does not fall into the catch.

I’ve tried with Exception, ErrorException Throable but none works, and I can’t understand what’s wrong.

Error example:

function logar($objectFactoryGeral,$toGeral){
    try {
        $SBLogin = $objectFactoryGeral->SBC_Usuario()->SBLogin();            
        $email = 59/0;//.$_REQUEST['email'];
        //$senha = $_REQUEST['senha'];            
        $toLogin = $toGeral->ITOLogin($email,$senha);        
        $SBLogin->logar($toLogin);
    } catch (Throwable $e) {
        return  RetornaExcecaoCOJS($e->getMessage());
    }        
}

1 answer

-1

I always create for every application I make a Handler error to handle the errors

function errorHandler($mensagem, 0, $level, $arquivo, $linha)//Transforma erros em Exceptions
{
   if(error_reporting() !== 0) //Para manter o operador @ funcionando
   {
      throw new ErrorException($mensagem, 0, $level, $arquivo, $linha)
   }
}

function exceptionHandler($exception)
{
   //O que você quiser fazer com o erro, exemplo:
   echo "<h1>Error</h1>";
   echo "<p>Mensagem:'". $exception->getMessage() ."</p>";
}

set_error_handler('errorHandler');//Transforma erros em exceções 
set_exception_handler('exceptionHandler');//Função que trata as exceções (e erros)

Only what is not caught by a catch will be handled by exceptionHandler

Browser other questions tagged

You are not signed in. Login or sign up in order to post.