PHP;从函数内部报告错误
PHP; Error reporting from inside a function
所以如果一个函数产生了一个 warning/notice 我们在函数中得到了 LINE。
我可以在函数调用之后 AND/OR 之前进行验证,但我很好奇是否有一种方法可以自动给出函数调用产生 LINE_ 的错误那个调用了函数?
您需要像这样使用 try catch 语句:
try{
//your code that errors here
}catch(Exception $e){
echo "Line number:" . $e->getLine();
//you could throw the exception here again
//throw $e;
//or create a new exception and throw that with the data you supply
//$newException = new Exception('New message goes here', 'exception code goes here');
//then throw it
//throw $newException;
exit;
}
这是文档的 link:
http://php.net/manual/en/exception.getline.php
您可能也对同样属于异常 class 的这些方法(以及其他方法)感兴趣:
- 获取消息
- 获取代码
- 获取文件
- 获取消息
根据您的评论并创建一个新的异常,请在此处查看异常 class:
使用 PHP IDE 调试器并设置断点,观察调用堆栈。
所以如果一个函数产生了一个 warning/notice 我们在函数中得到了 LINE。
我可以在函数调用之后 AND/OR 之前进行验证,但我很好奇是否有一种方法可以自动给出函数调用产生 LINE_ 的错误那个调用了函数?
您需要像这样使用 try catch 语句:
try{
//your code that errors here
}catch(Exception $e){
echo "Line number:" . $e->getLine();
//you could throw the exception here again
//throw $e;
//or create a new exception and throw that with the data you supply
//$newException = new Exception('New message goes here', 'exception code goes here');
//then throw it
//throw $newException;
exit;
}
这是文档的 link:
http://php.net/manual/en/exception.getline.php
您可能也对同样属于异常 class 的这些方法(以及其他方法)感兴趣:
- 获取消息
- 获取代码
- 获取文件
- 获取消息
根据您的评论并创建一个新的异常,请在此处查看异常 class:
使用 PHP IDE 调试器并设置断点,观察调用堆栈。