douao1854 2014-02-20 15:19
浏览 87
已采纳

从set_exception_handler函数中获取异常名称

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 ?

  • 写回答

1条回答 默认 最新

  • dongre8505 2014-02-20 15:41
    关注

    try

    $exceptionClass = get_class($msg);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?