我想捕获此错误:
$a[1] = 'jfksjfks'; try { $b = $a[0]; } catch (\Exception $e) { echo "jsdlkjflsjfkjl"; }
编辑: 实际上,我在以下行中收到此错误: $parse = $xml->children[0]->children[0]->toArray();
$parse = $xml->children[0]->children[0]->toArray();
您需要定义您的自定义错误处理程序,例如:
<?php set_error_handler('exceptions_error_handler'); function exceptions_error_handler($severity, $message, $filename, $lineno) { if (error_reporting() == 0) { return; } if (error_reporting() & $severity) { throw new ErrorException($message, 0, $severity, $filename, $lineno); } } $a[1] = 'jfksjfks'; try { $b = $a[0]; } catch (Exception $e) { echo "jsdlkjflsjfkjl"; }