Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

catching general exceptions before

 
Romeo Ranjan
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
source: Examlab for SCJP 6.0


compiling the above code,this is the error that i get.


can someone explain me why i get this? I understand that Exception is more general when compared to RuntimeException which is specific?the answer should have been e.am i wrong?RuntimeException IS A Exception,is that correct??
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Romeo Ranjan wrote:RuntimeException IS A Exception,is that correct??

What JavaDocs says ?

And about error, study the multiple catch block defining rules.
 
Rohan kanade
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
RunTimeException is a subclass of Exception , So it must be declared in a catch clause before Exception because it is narrower/precise than Exception.

btw you can neglect catching a runtimeException, it and its subclasses are unchecked exceptions.
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rohan kanade wrote:RunTimeException is a subclass of Exception , So it must be declared in a catch clause before Exception because it is narrower/precise than Exception.....
you can neglect catching a runtimeException,

Please be serious with the class names.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic