set_error_handler(function($err_severity, $err_msg, $err_file, $err_line, array$err_context){ throw new ErrorException($err_msg, 0, $err_severity, $err_file, $err_line); }, E_WARNING); try{ $resource = file_get_contents($url); } catch(Exception $e){ $error = $e -> getMessage(); if(!empty($error)) die("<pre><b>获取数据失败\r\n$error\r\n</b></pre>"); } # restore the previous error handler 还原以前的错误处理程序 restore_error_handler();