2017-06-03 58 views
0

我遇到問題。 Throwable不會爲要求或包含函數返回異常。有什麼方法可以「修復」嗎?代碼:Throwable not catchching include並要求

try { 
    include 'non-existent-file.php'; 
    #require 'non-existent-file.php'; 
} catch (\Throwable $ex) { 
    die('include error'); 
} 

非常感謝您的幫助。

+0

誰告訴你的東西將在這裏拋出? –

回答

0

你有沒有想過使用file_exists (string $filename)的...

if (file_exists('non-existent-file.php') === true) { 
    include 'non-existent-file.php'; 
} 
else { 
    die('include error'); 
} 
+0

當然,這就是我關心的捕捉異常並顯示自己的消息。 – Trawlr