Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Throwable

 
krussi rong
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
here is the question:

which of the following must be true of the object
thrown by a throw statement?
1.It must be assignable to the Throwable type.
2.It must be assignable to the Error type.
3.It must be assignable to the Exception type.
4.It must be assignable to the String type.
so why the answer is 1 ?
but I think is 1.2.3
thanks
Jenny
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exceptions and Errors are descendents of the class Throwable. You are only allowed to throw any object that descends from Throwable.
As Error and Exception are siblings, if #2 was true, you couldn't throw Exceptions and if #3 was true, you couldn't throw Errors.
The only correct answer is #1.
I hope that helps,
Corey
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's the "must be" that makes it only #1. It can be assignable to Exception (since Exception is a child of Throwable) but it must be assignable to Throwable.
 
krussi rong
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks guys!
Krussi
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic