[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Jeanne Boyarsky wrote:The problem is "may not" means two things in English depending on where you put the emphasis:
1) you may NOT - means you are not allowed to
2) you MAY not - you might or might not do something
Mohammad Ali Asgar wrote:Another observation is that the code does not need to import NullPointerException, which I find quite logical, since it is about real-time.
In the case of IOException, which is a compile-time/checked exception, it does not compile. An "import" statement is required for IOException in order for the compiler to recognize it. Again, that is logical, since it is checked at compile-time.
Joanne
Mohammad Ali Asgar wrote:...real-time exception...real-time exceptions...real-time exceptions...real-time exceptions.
Joanne
Mohammad Ali Asgar wrote:Another observation is that the code does not need to import NullPointerException, which I find quite logical, since it is about runtime.
In the case of IOException, which is a compile-time/checked exception, it does not compile. An "import" statement is required for IOException in order for the compiler to recognize it. Again, that is logical, since it is checked at compile-time.
Mohammad Ali Asgar wrote:But if NullPointerException is replaced by InterruptedException, then the compiler reports an error that in the signature of methodA the "throws" clause is missing. That indicates that it is mandatory for a method to declare that it throws a checked exception, if there is a "throw" statement within that method.
Roel De Nijs wrote:And what would happen if you combine both options? So if you would handle-and-declare the checked exception?
Ooh, so much fun with such a small code snippet
Prepare for 'OCA Java SE 8 certification' with eJavaGuru.com
Author of Manning's OCA Java SE 8 bookProgrammer I Certification Guide, OCA Java SE 7 Programmer I Certification Guide and OCP Java SE 7 Programmer II Certification Guide
Mala Gupta wrote:So you can do both-catch an exception and declare it to be thrown.
Mala Gupta wrote:Can you 'catch' an exception, if the enclosing try block doesn't throw it?
Mala Gupta wrote:Will the preceding code compile, when IOException is replaced by-
Ruth Stout was famous for gardening naked. Just like this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|