[英]PHP Try-Catch Failing to Catch (Not a 'Warning')
我有一些PHP代碼應引起並捕獲兩個異常:
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(AuthenticationException $e) {} // DOESN'T WORK - Passed to the exception handler.
echo 'Not executed!'; // This isn't executed.
我試着將它們概括為catch(Exception $e)
但是遇到了同樣的問題……不知道為什么。
有什么幫助嗎?
OK,我發現這是一個命名空間的問題:它似乎在嘗試和PHP不會抱怨use
(在這種情況下不存在的命名空間中的元素use Framework\\AuthenticationException
當我真的需要use Framework\\Connector\\AuthenticationException
)。 現在一切都變淡了:)
干杯
您還應該知道,在PHP中使用@非常慢。 拜托,拜托,請不要在生產代碼中使用它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.