简体   繁体   English

jdb打印捕获到异常消息

[英]jdb print caught exception message

I have exceptions thrown in my java code when an error occurs. 发生错误时,我的Java代码中会引发异常。 I then run the code using jdb so when the exception occurs, I can see the state that the code is in and debug. 然后,我使用jdb运行代码,以便在发生异常时,可以看到代码所在的状态并进行调试。 For all exceptions that I throw, I put in a useful string message. 对于抛出的所有异常,我都输入了有用的字符串消息。 However, when jdb catches the exception, it doesn't print this string along with it. 但是,当jdb捕获异常时,它不会随该字符串一起输出。 How do I print this string? 如何打印此字符串?

I have googled and searched and read the documentation but I can't figure out how. 我已经用Google搜索和搜索并阅读了文档,但是我不知道如何操作。

If I have the test class: 如果我有考试班:

public class Test{
    public static void main(String[] args){
        throw new IllegalArgumentException("How do I view this string through jdb?");
    }
}

And run it through jdb: 并通过jdb运行它:

$ jdb Test
Initializing jdb ...
> run
run Test
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
> 
VM Started: 
Exception occurred: java.lang.IllegalArgumentException (uncaught)"thread=main", Test.main(), line=3 bci=9

main[1] 

Check out the JDB "catch" command, for example "catch IllegalArgumentException". 签出JDB的“ catch”命令,例如“ catch IllegalArgumentException”。 Per the JDB docs , it will cause the debugger to break when the exception is thrown so that you can probe into the details. 根据JDB 文档 ,当引发异常时,它将导致调试器中断,以便您可以探究细节。 This document on debugging does a nice job explaining some of the downsides to being dependant on "print" statements, and also references the JDB "catch" functionality. 这份关于调试的文档很好地解释了依赖于“ print”语句的一些缺点,并且还引用了JDB的“ catch”功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM