关于PHP中的错误处理 - 据我所知,有3种样式:
die()或exit()风格:
$con = mysql_connect("localhost","root","password");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
Run Code Online (Sandbox Code Playgroud)throw Exception 样式:
if (!function_exists('curl_init')) {
throw new Exception('need the CURL PHP extension.
Recomplie PHP with curl');
}
Run Code Online (Sandbox Code Playgroud)trigger_error() 样式:
if(!is_array($config) && isset($config)) {
trigger_error('Error: config is not an array or is not set', E_USER_ERROR);
}
Run Code Online (Sandbox Code Playgroud)现在,在PHP手册中使用了所有三种方法.
我想知道的是我应该选择哪种风格?为什么?
这3个是否相互替换,因此可以互换使用?
稍微OT:是否只是我或每个人都认为PHP错误处理选项太多,以至于它让php开发人员感到困惑?