【问题标题】:Get exception name from set_exception_handler function从 set_exception_handler 函数获取异常名称
【发布时间】:2014-02-20 15:19:40
【问题描述】:

我有几个例外:

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

这里是异常处理程序

 set_exception_handler('get_exceptions');

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

示例错误

 if(0){
    throw new fooException;  
 }

 if(!1){
   throw new barException;  
 }

现在,在get_exceptions 函数中,我正在尝试但无法获取抛出的异常类型,而不是消息、代码和整个数据。只是类的名称,如fooExceptionbarException 无论如何只能获取触发异常的名称?

【问题讨论】:

    标签: php oop exception exception-handling


    【解决方案1】:

    试试

    $exceptionClass = get_class($msg);
    

    【讨论】:

    • 不。我试过但没有这样做。另外,您要的是类名,而我要的是异常名称
    • 那么,定义“异常名称”。它是什么?在您的问题中,您想要“只是类的名称,例如 fooException 或 barException”。这些肯定可以通过使用 get_class()
    • 好吧,我试过了,我告诉你。它完全没有回应
    猜你喜欢
    • 2021-09-27
    • 2021-08-19
    • 2013-07-19
    • 1970-01-01
    • 2021-04-11
    • 2017-05-08
    • 2010-10-08
    • 2012-09-25
    • 1970-01-01
    相关资源
    最近更新 更多