aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes runtime exceptions thrown by overridden functions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "runtime exceptions thrown by overridden functions" Watch "runtime exceptions thrown by overridden functions" New topic
Author

runtime exceptions thrown by overridden functions

Rachel Glenn
Ranch Hand

Joined: Oct 24, 2012
Posts: 95
I have this code:




and the following code that creates and calls the above...




WHY is this alllowed to compile? The overriden function in class Derived is specifying an exception (NumberFormatException) that is not specified/declared by the Base class. From my understanding it is allowed to compile because NumberFormatException is a runtime exception and not a checked exception, correct?

How do you know, in general,if "xxxException" is a runtime exception or a checked exception ? Is this something that you have to memorize???
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2861
    
  11

Rachel Glenn wrote:
WHY is this alllowed to compile? The overriden function in class Derived is specifying an exception (NumberFormatException) that is not specified/declared by the Base class. From my understanding it is allowed to compile because NumberFormatException is a runtime exception and not a checked exception, correct?


That's exactly right.

Rachel Glenn wrote:
How do you know, in general,if "xxxException" is a runtime exception or a checked exception ? Is this something that you have to memorize???


Well, you have to memorize that unchecked exceptions are the ones that are subclasses (directly or indirectly) of Error or RuntimeException. You can then look up your exception in JavaDocs and see its class hierarchy. For certification exams, they may want you to memorize, for a small set of exception classes, which are checked or unchecked. I'm not sure what that list is, but I bet it's fairly short. NumberFormatException is probably on it though.
Rachel Glenn
Ranch Hand

Joined: Oct 24, 2012
Posts: 95
Greg Charles wrote:
Rachel Glenn wrote:
WHY is this alllowed to compile? The overriden function in class Derived is specifying an exception (NumberFormatException) that is not specified/declared by the Base class. From my understanding it is allowed to compile because NumberFormatException is a runtime exception and not a checked exception, correct?


That's exactly right.

Rachel Glenn wrote:
How do you know, in general,if "xxxException" is a runtime exception or a checked exception ? Is this something that you have to memorize???


Well, you have to memorize that unchecked exceptions are the ones that are subclasses (directly or indirectly) of Error or RuntimeException. You can then look up your exception in JavaDocs and see its class hierarchy. For certification exams, they may want you to memorize, for a small set of exception classes, which are checked or unchecked. I'm not sure what that list is, but I bet it's fairly short. NumberFormatException is probably on it though.


ugh! thanks! I can't memorize to save my life!!! But I will do my best....

 
wood burning stoves
 
subject: runtime exceptions thrown by overridden functions