Which statement is true?
A. catch(X x) can catch subclasses of X.
B. The Error class is a RuntimeException.
C. Any statement that can throw an Error must be enclosed in a try block.
D. Any statement that can throw an Exception must be enclosed in a try block.
E. Any statement that can throw a RuntimeException must be enclosed in a try
block.
Answer: A
Error and Exception are subclasses of Throwable.
RuntimeException is a subclass of Exception.
statements that throw Error do not need to be in a try block.
statemens that throw RuntimeException do not need to be in a try block (but other Exceptions have to be).
本文探讨了Java中的异常处理机制,解析了Error与Exception的区别及如何正确处理不同类型的异常。文章指出,catch子句可以捕获及其子类的异常,而不需要将抛出Error或RuntimeException的语句置于try块中。
540

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



