PHP Try-Catch Failing to Catch (Not a 'Warning')
I have some PHP code that should cause and catch two exceptions:
try{
@$this->connector->connect(); // Suppress the default warning (doesn't effect 'throw')
} catch(BadArgumentException $e) {} // Works, no error, following code executes.
try{
@$this->connector->connect(array('user' => 'Doesn\'t exist', 'pass' => 'invalid'));
} catch(Aut开发者_JAVA百科henticationException $e) {} // DOESN'T WORK - Passed to the exception handler.
echo 'Not executed!'; // This isn't executed.
I have tried generalising them to catch(Exception $e)
but get the same problem... no idea why.
Any help?
OK I found out it was a namespacing problem: it seems PHP doesn't complain when you try and use
a non-existant namespaced element (in this case use Framework\AuthenticationException
when really I needed use Framework\Connector\AuthenticationException
). Everything's peachy now :)
Cheers
You should also know that using @ is EXTREMELY slow in PHP. Please, please, please don't use it in your production code.
精彩评论