Jump to content

maneja excepciones de php


Recommended Posts

lo que aremos a continuacion sera crear una clase llamada customException que extienda la clase por defecto Exception

luego la funcion errormesage

 

Cuando llamamos errores la sentencia es $e->getMessage() u otros asi pero estamos extendiendo la class Exception por lo que quedaran todos los metodos en $this->

class customException extends Exception
{
public function errorMessage()
  {
  //error message
  $errorMsg = 'Error en la linea '.$this->getLine().'<br><b>'.$this->getMessage().'</b>';
  return $errorMsg;
  }
}

 

ejemplo de uso :cafe:

 

creamos un try and catch y usamos throw para capturar el error

try{
    $start=new core();
    if(!$start){
        throw new customException($start);
        //si llegamos aqui ubo exito
    }
}catch(customException $e){
        echo $e->errorMessage();
    }

 

 

saludos :)

Edited by gmafuken
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...