2015-04-06 126 views
3

我有一个PHP函数,当我遇到异常时调用。它可以接受一个例外,因为可选参数,因此它可以显示它用于调试目的:PHP:打印捕获异常像Xdebug

public static function notFound($resource, \Exception $exception = null) { 
    // [... normal error handling ...] 

    if (DEBUG && $exception != null) { 
     echo '<br><br><h2>Stacktrace:</h2>'; 
     print_r($exception);   
    } 
    die(); 
} 

我想什么是显示此异常以同样的方式捕获的异常和警告显示与Xdebug的(风格的CSS和HTML ,可能采用不同的配色方案)。像这样(由echo $exception->getTrace();创建):

enter image description here

如果我使用print_r($exception);我得到这个,这似乎至少包含一些必要的输出为XDebug的:

enter image description here

我有尝试echo $exception->xdebug_message;,var_dump($exception);var_dump($exception->xdebug_message);,但它们都没有工作。最后一个似乎是封闭的,以我想要的,但我不能让它正常工作:

enter image description here

是否有使用Xdebug的造型为捕获的异常的方法吗?

回答

1

好吧,我发现在all xdebug functions此列表中的解决方案:

xdebug_print_function_stack($exception); 
+0

这将打印当前栈,而不是例外堆栈。 – felixfbecker 2016-03-21 22:46:14