Try/Catch block in PHP not catching Exception

后端 未结 12 799
既然无缘
既然无缘 2020-12-04 13:45

I am trying to run this Example #1 from this page: http://php.net/manual/en/language.exceptions.php



        
12条回答
  •  眼角桃花
    2020-12-04 14:20

    I just had this exact problem where it seemed like I had even copied the name of the exception and yet it didn't catch it. It turned out it was my stupid mistake but I thought I should post my case here in case there is someone else in the same situation.

    I had my exception in my namespace called A and the script was in a namespace called B. The problem was that I had A\MyException which equals (in PHP) \B\A\MyException (because my script is in the namespace called B!). All I had to do to fix it was to add backslash (or whatever it's called) to the exception name so it would look like this: \A\MyException

提交回复
热议问题