简体   繁体   English

在带有2个引发异常的内部函数的try-catch中,无法使用包装函数捕获PHP中的异常

[英]Not able to catch an exception in PHP with wrapper function in a try-catch with 2 inner functions that throw exceptions

I have a wrapper function in a class xyz.php class within foreach loop as below and other abc.php class. 我在下面的foreach循环以及其他abc.php类的xyz.php类中有一个包装函数。 My catch block doesn't get executed when an exception is thrown from inner methods of wrapper class. 从包装类的内部方法引发异常时,我的catch块不会执行。

xyz.php class xyz.php类

foreach($rss as $rs){
  try{
     //Included file abc.php class
     $rs->wrapper();
   } catch (exception $e){
      //debug message that displays exception.
      throw $e;
   }
}

abc.php class abc.php类

public function wrapper(){
   $this->function_throws_exception1();
   $this->function_throws_exception2();
}

Both classes are under different namespaces. 这两个类都在不同的名称空间下。 It is something related to namespace looks like. 它是与名称空间相关的东西。 Just adding \\ before exception resolved it. 仅在异常解决之前添加\\。 catch (\\exception $e)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM