• Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception handling  RSS feed

 
Pooja Pawar
Greenhorn
Posts: 8
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



In the above code Arrayoutofboundexception is thrown. As it is a subclass of Runtime exception which is a subclass to Exception then why MyException (which is a subclass to Exception)  is not catching the exception?I am new to java and trying to understand this.
 
Paul Clapham
Sheriff
Posts: 22832
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You say ArrayOutOfBoundsException is a subclass of Exception. Okay... so if your code was written to catch Exception, it would also catch ArrayOutOfBoundsException.

It's also true that MyException is a subclass of Exception. But is ArrayOutOfBoundsException a subclass of MyException? No, it isn't. So catching MyException shouldn't catch ArrayOutOfBoundsException.
 
Pooja Pawar
Greenhorn
Posts: 8
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.
Now I understood the difference  that MyException may also be any other sibling class to Arrayoutofboundexception.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!