获取局部变量
当从已部署的应用程序获取堆栈跟踪作为错误报告时,获取实际变量值以重建抛出异常之前的系统状态也会很有帮助。
类似的事情在 Java 中可行吗?如何才能做到这一点?
干杯, 最大限度
When getting a stacktrace as error report from an application that is already deployed, it would be helpful to also get the actual variable values to reconstruct the system's state at the point before the exception was thrown.
Is anything like that feasible in Java and how could one do that?
Cheers,
Max
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我很确定您无法获取堆栈跟踪中的局部变量,因为输出是从 StackTraceElement 实例构建的,该实例仅包含类、文件、方法和行号(请参阅 http://download.oracle.com/javase/6/docs/api/java/lang/ StackTraceElement.html)。
I'm pretty sure you cannot get the local variables in the stacktrace as the output is built from instance of StackTraceElement which only contains, the class, the file, the method and the line number (see http://download.oracle.com/javase/6/docs/api/java/lang/StackTraceElement.html).
看看这个工具:
http://www.chrononsystems.com/
它允许您跟踪堆栈跟踪,可以选择在应用程序的时间轴中返回过去。我自己还没有尝试过,但对于您所指的情况类型(意外异常)来说,它看起来确实很有希望。
很高兴听到它是否有帮助:)
Have a look at this tool:
http://www.chrononsystems.com/
It allows you to keep track of the stack trace with the option to go back in time in the application's timeline. I haven't tried it myself but it looks really promising for the type of situation you are referring to (unexpected Exceptions).
It will be good to hear if it helped :)
如果您使用诸如Eclipse之类的IDE - 您可以使用调试工具在程序的整个执行过程中查看这一点。
If you use an IDE such as Eclipse - you can use debugging tools to view this through the entire execution of the program.
发生这种情况的唯一方法是,是否可以通过异常捕获链中较高的可用变量或通过异常对象本身(在自定义异常的情况下)访问相关系统状态:
The only way that's going to happen is if the system state in question is reachable through either variables available higher up in the exception-catching chain, or via the exception object itself (in the case of a custom exception):