• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

which of the statements are true...

 
Supriya Nimakuri
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A. catch(X x) can catch subclasses of X.
B. Any statement that can throw an Exception must be enclosed in a try block.

I guess Statement B is true..if not why..

Regards
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, RuntimeException, Error, and their subclasses are unchecked exceptions. Code that may throw them is not required to be in a try block nor is the exception required to be listed in the throws clause of the method containing the code.
 
Naseem Khan
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Second part is same as your previous thread throw where i gave its explanation.
 
Karol Kisielewski
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Supriya Nimakuri:
A. catch(X x) can catch subclasses of X.
B. Any statement that can throw an Exception must be enclosed in a try block.

I guess Statement B is true..if not why..

Regards


B. No, because the method inside which the statement exists can propagate the exception up via method's throws clause without enclosing the statement in try-catch block.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic