Ari*_*iod 3 php exception-handling
我试图捕获一个运行时异常,该异常将由一个函数抛出,该函数基本上只是oci_execute()的包装函数.例如:
try {
$SQL = "INSERT";
ExecuteQuery($SQL);
} catch (Exception $e) {
echo "<p>There was an error.</p>";
echo $e->getMessage();
}
Run Code Online (Sandbox Code Playgroud)
但是,似乎没有抓住异常:
...
ociexecute() [function.ociexecute]: ORA-00925: missing INTO keyword
...
Run Code Online (Sandbox Code Playgroud)
我在这里错过了什么吗?
它看起来像是在触发错误而不是抛出异常.
您可以使用以下方法将错误转换为异常set_error_handler():
function errorHandler($number, $string, $file = 'Unknown', $line = 0, $context = array())
{
if (($number == E_NOTICE) || ($number == E_STRICT))
return false;
if (!error_reporting())
return false;
throw new Exception($string, $number);
return true;
}
set_error_handler('errorHandler');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6409 次 |
| 最近记录: |