如何使用PHPseclib捕获未处理的错误?

假设我有以下代码.

为了测试这一点,我更改了服务器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.
}

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...