简体   繁体   中英

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. My catch block doesn't get executed when an exception is thrown from inner methods of wrapper class.

xyz.php class

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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