Win a copy of Python Continuous Integration and Delivery this week in the Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

Java OCA 8 Chapter 6 - Exceptions - Review Questions Ex 19  RSS feed

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


A. Exception
B. IOException
C. IllegalArgumentException
D. RuntimeException
E. StackOverflowError
F. None of the above.

Answer is CE.

Option E is allowed because it isn’t in the same inheritance tree as RuntimeException.



I read the solution on option E but I have no idea why it is a correct answer. StackOverflowError inherits java.lang.Error. I mean, yes they are in the same inheritance tree (Throwable) but checked exception also in that inheritance tree as well. Please help, thanks.



 
Ranch Hand
Posts: 32
Android Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't put a catch clause that catches a Superclass above a catch clause that catches a subclass. So in this example the catched exception can't be a Superclass of Runtime exception. StackOverflowError is a subclass of throwable but it isn't in the same branch of the tree as Runtime exception because it is an error. So it is allowed because StackOverflowError isn't a Superclass of Runtime exception.
 
Marshal
Posts: 63314
205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good answer, but why isn't IOException permissible?

BTW: OP, please indicate where the blank is. Was it line 6? I think it would be easy to find had you written the code like this:-
 
Micheal Bush
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Good answer, but why isn't IOException permissible?

BTW: OP, please indicate where the blank is. Was it line 6? I think it would be easy to find had you written the code like this:-



I put an underline there. Can I say IOException is checked exception; therefore, it is not in the same inheritance branch as RuntimeException.
 
author & internet detective
Posts: 39148
724
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Micheal Bush wrote:Can I say IOException is checked exception; therefore, it is not in the same inheritance branch as RuntimeException.


This is true.

However, you can't put IOException there.Java is smart enough to recognize that the code in the try block couldn't possibly throw an IOException. So it won't compile because of that.
 
Never trust an airline that limits their passengers to one carry on iguana. Put this tiny ad in your shoe:
Become a Java guru with IntelliJ IDEA
https://www.jetbrains.com/idea/
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!