• 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
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

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

 
Greenhorn
Posts: 26
  • 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: 62231
193
  • 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
Greenhorn
Posts: 26
  • 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: 39076
714
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.
 
The happiness of your life depends upon the quality of your thoughts -Marcus Aurelius ... think about this tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!