Try/Catch block in PHP not catching Exception

后端 未结 12 805
既然无缘
既然无缘 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:39

    Quite old question, yet...

    I had this problem as well (and that's how I found this post) but just simple experiment allowed me to find the solution. Just try changing Exception to \Exception. Worked for me!

    EDIT:

    As sivann pointed in the comments, using namespace should do the same thing. So simply put use \Exception as Exception; before your class declaration.

提交回复
热议问题