jQuery in Action, 3rd edition
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes exam lab q-9(excepton handling) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "exam lab q-9(excepton handling)" Watch "exam lab q-9(excepton handling)" New topic
Author

exam lab q-9(excepton handling)

Arjun Srivastava
Ranch Hand

Joined: Jun 23, 2010
Posts: 432


above code works fine.
but at line 1 ,run-time exception has never been thrown,so i guess it should be the error coz "i have read not to use the exception that has never been thrown in corresponding try block else compiler error".
please justify above statement.why it is not error?


SCJP 6 | FB : Java Certifications-Help. | India Against Corruption
Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

Howdy Arjun!

The RuntimeExceptions are not checked if they are thrown from the try block, because they are... unchecked.

They can occur or don't so there is no way you can say they will ever be thrown from the try clause.
Arjun Srivastava
Ranch Hand

Joined: Jun 23, 2010
Posts: 432

Pedro Kowalski wrote:Howdy
The RuntimeExceptions are not checked if they are thrown from the try block, because they are... unchecked.
They can occur or don't so there is no way you can say they will ever be thrown from the try clause.

howdy
that means RuntimeExceptions if used unnecessarily in catch will not harm.
but checked exceptions are evil in this case.
Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

Just try it for yourself:



Will it compile?
Arjun Srivastava
Ranch Hand

Joined: Jun 23, 2010
Posts: 432

Pedro Kowalski wrote:Just try it for yourself:

Will it compile?


offcourse yes,works fine.
Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

Hope that helped mate :-)

Cheers!
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Hey Arjun! If the compiler checks whether the exception will be thrown or not, then that exception IS NOT a RuntimeException at all!


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Arjun Srivastava
Ranch Hand

Joined: Jun 23, 2010
Posts: 432

yes,thanks.
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: exam lab q-9(excepton handling)
 
It's not a secret anymore!