[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
Kendall Ponder wrote:Is there a way to reason which exceptions are checked or unchecked or do I just need to memorize the lists?
Roel De Nijs wrote:
Kendall Ponder wrote:Is there a way to reason which exceptions are checked or unchecked or do I just need to memorize the lists?
There's not really a way to reason, but luckily the rule to remember for checked/unchecked exceptions is pretty straightforward and easy to remember: All exceptions are checked exceptions, except for those indicated by Error, RuntimeException, and their subclasses. That's simple, isn't it?
Enthuware - Best Mock Exams and Questions for Oracle Java Certifications
Quality Guaranteed - Pass or Full Refund!
Kendall Ponder wrote:
I found a useful list of checked vs unchecked exceptions on another thread here. One of the comments pointed out that all RuntimeExceptions were unchecked which I thought would be helpful to remember which was which but IOException is a checked exception and it clearly only happens at run time. The compiler can't know the file doesn't exist until the program runs. Is there a way to reason which exceptions are checked or unchecked or do I just need to memorize the lists? Thanks!
Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Raghavan Muthu wrote:
The fact why IOException has been classified as a Checked Exception is that the file may or may not really exist which can be determined ONLY at the runtime. However the Programmer/Developer is excepted to know that there is a potential risk (of the file not being present) and he should really be accounting that risk while coding and he should have handled a way to deal with the exception(al scenario).
Raghavan also wrote:
Coming to your other dimension of why it is not a runtime exception is that the runtime exceptions are generally caused by the input fed by the user and he can very well take care of it. So it does not need to be taken care in a proactive fashion.
Kendall Ponder wrote:
IOException is a checked exception and it clearly only happens at run time.
Guillermo Ishi wrote:I think checked means checked by the compiler
Kendall Ponder wrote:The rule is simple but I would need to know which exceptions were subclasses of RuntimeException and which were not and as far as I can tell the only way to do that is to memorize whether each exception is a subclass of RuntimeException.
Kendall Ponder wrote:Maybe I am missing something but it isn't clear to me why IOException is not a RuntimeException and NullPointerException is. I assume NullPointerException is unchecked because the possibility of a NullPointerException is so prevalent.
You may have just won ten million dollars! Or, maybe a tiny ad.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|