Question

I have a couple of exception ex:

fooException extends Exception{}
barException extends Exception{}
tarException extends Exception{}

here is the exception handler

 set_exception_handler('get_exceptions');

  function get_exceptions($msg){
    # how to get the exception name here like
    # fooException barException
  }

example errors

 if(0){
    throw new fooException;  
 }

 if(!1){
   throw new barException;  
 }

Now, inside the get_exceptions function I am trying but unable to get what exception type that is being thrown, instead of the the message, code and the whole data. just the name of the class, like fooException or barException is there anyway to get only the name of the triggered exception ?

Was it helpful?

Solution

try

$exceptionClass = get_class($msg);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top