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

doubt in Exception

 
Max White
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I was trying something and came across the below scenario.

When I try to compile the above code ,I get a compilation error-> Unreachable catch block..(as there is nth in the try block to throw SQLException)
But if I change the above code to

It compiles without any error.
Why Exception class is being given a special treatment?
Thanks.
 
Sresh Rangi
Ranch Hand
Posts: 52
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Catching exception covers RuntimeExceptions which are unchecked. In general, the compiler doesn't know what unchecked exceptions can be thrown in the try block, so it can't warn you about unreachable catch blocks involving them.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sresh Rangi is right.

but compiler is not that smart in 2nd case though ;)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic