如何使用PHPseclib捕获未处理的错误?
发布时间:2020-12-13 14:08:20 所属栏目:PHP教程 来源:网络整理
导读:假设我有以下代码. 为了测试这一点,我更改了服务器IP以模仿错误消息.下面的IP不存在,因此Unhandled Exception消息为:无法连接到10.199.1.7.错误113.无主机路由 这会显示一个带有PHP代码的丑陋屏幕.是否有可能发现此错误? try { $ssh = new Net_SSH2('10.19
假设我有以下代码.
为了测试这一点,我更改了服务器IP以模仿错误消息.下面的IP不存在,因此Unhandled Exception消息为:无法连接到10.199.1.7.错误113.无主机路由 这会显示一个带有PHP代码的丑陋屏幕.是否有可能发现此错误? try { $ssh = new Net_SSH2('10.199.1.7'); if (!$ssh->login('deploy',$key)) { throw new Exception("Failed login"); } } catch (Exception $e) { ??? }
通过图书馆看.
user_error('Connection closed by server',E_USER_NOTICE); 它会触发错误.您可以使用http://php.net/manual/en/function.set-error-handler.php处理这些错误 例如 // Your file.php $ssh = new Net_SSH2('10.199.1.7'); $ssh->login('deploy',$key); // bootstrap.php // This will catch all user notice errors!!! set_error_handler ('errorHandler',E_USER_NOTICE) function errorHandler($errno,$errstr,$errfile,$errline) { echo 'Error'; // Whatever you want to do. } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |