Q:
I am wirting a code in which an exception is thrown, I catch this exception in the catch block, but when I display e.getMessage() it displays null.....Can any body help in telling why....
A:
getMessage() is just about useless.
If you use the no-arg constructor for a Throwable, you'll get a null message.
Much, much better for displaying information about Throwables is toString() which will include the class name of the Throwable and the message if it's not null.
Out shop never uses getMessage()
本文解答了一个关于Java异常处理的问题:当捕获异常并尝试显示其消息时遇到null值的情况。文章解释了使用toString()方法相较于getMessage()方法的优势,并提供了解决方案。
1507

被折叠的 条评论
为什么被折叠?



