【发布时间】:2012-11-27 16:04:30
【问题描述】:
如何获取访问方法的行?
方法:
function configure($newFile = false){
try {
...
throw new Exception("Error X");
} catch (Exception $e) {
$exception = "<b>Caught exception: </b>\n<blockquote>"
.$e->getMessage()
."</blockquote>"
."\n"."on line <b>"
.$e->getLine()
."</b> of <i>"
.$e->getFile()
."</i>";
echo $exception;
}
}
输出是这样的:
Caught exception:
Error X
on line 25 of C:\xampp\htdocs\MgFramework\classes\MgDatabase.class.php
但我想显示访问该方法的行和文件:
$database = new MgDatabase();
$database->configure();
有可能吗?
谢谢!
【问题讨论】:
-
Psst,你可能想read the Exception class manual page,因为它列出了所有可用的方法。其中一个或多个是您正在寻找的。span>
-
答案隐藏在每个异常对象中可用的堆栈跟踪中。