aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes doubt in Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "doubt in Exception" Watch "doubt in Exception" New topic
Author

doubt in Exception

Max White
Ranch Hand

Joined: Jun 28, 2008
Posts: 83
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
Greenhorn

Joined: Nov 28, 2012
Posts: 9
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

Joined: Jan 28, 2008
Posts: 5575

Sresh Rangi is right.

but compiler is not that smart in 2nd case though ;)
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: doubt in Exception
 
Similar Threads
try..catch block
jsp and jdbc
ex.getNextException();
Onchange JCombobox
Exceptions error