Try/Catch block in PHP cannot catch exception situations
P粉226413256
P粉226413256 2023-08-22 15:19:37
0
1
453

I'm trying to run this example #1, from this page: http://php.net/manual/en/language.exceptions.php

getMessage(), "n"; } // Continue execution echo "Hello Worldn"; ?>

However, the output I get is not expected:

0.2 Fatal error: Uncaught exception 'Exception' with message 'Division by zero.' inxxx: 7 Stack trace: #0 xxx(14): inverse(0) #1 {main} thrown in xxx on line 7

The development environments I use are UniServer 3.5 and PHP 5.2.3

P粉226413256
P粉226413256

reply all (1)
P粉611456309

I just ran into this exact problem, it feels like I've even copied the name of the exception and it's not catching it. Turns out to be a stupid mistake on my part, but I thought I'd post my situation here in case anyone else is in the same situation.

My exception is calledAin my namespace and the script is calledBin one namespace. The problem is that I have aA\MyExceptionwhich is equal (in PHP) to\B\A\MyException(because my script is calledB# in the namespace ##!). All I had to do was add a backslash (or whatever it was called) before the exception name to fix it so it looked like this:\A\MyException

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!