{ "NullPointerException" : { "Exception in thread "main" java.lang.NullPointerException", {"Book.java:16" : "com.example.myproject.Book.getTitle", "Author.java:25" : "at com.example.myproject.Author.getBookTitles", "Bootstrap.java:14" : "at com.example.myproject.Bootstrap.main()" } }, "Caused By" : { "Exception in thread "main" java.lang.NullPointerException", {"Book.java:16" : "com.example.myproject.Book.getTitle", "Author.java:25" : "at com.example.myproject.Author.getBookTitles", "Bootstrap.java:14" : "at com.example.myproject.Bootstrap.main()" } }}
您可以像这样遍历异常:
catch (Exception cause) { StackTraceElement elements[] = cause.getStackTrace(); for (int i = 0, n = elements.length; i < n; i++) { System.err.println(elements[i].getFileName() + ":" + elements[i].getLineNumber() + ">> " + elements[i].getMethodName() + "()"); }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)