Forums Register Login

Unchecked exceptions

+Pie Number of slices to send: Send
For the purpose of exam, do we need to know all unchecked exceptions by name, so that we don't worry about handling them? I understand checked exceptions should be declared or handled, and unchecked exception don't have to. Or is it safe to assume the only unchecked exception (not Error) that will appear in the exam will be RuntimeException only?
If not, is it true to say all subclasses of RuntimeException are the only unchecked exceptions?.. as the list shown below:
--------------------
class java.lang.RuntimeException
class java.lang.ArithmeticException
class java.lang.ArrayStoreException
class java.lang.ClassCastException
class java.lang.IllegalArgumentException
class java.lang.IllegalThreadStateException
class java.lang.NumberFormatException
class java.lang.IllegalMonitorStateException
class java.lang.IllegalStateException
class java.lang.IndexOutOfBoundsException
class java.lang.ArrayIndexOutOfBoundsException
class java.lang.StringIndexOutOfBoundsException
class java.lang.NegativeArraySizeException
class java.lang.NullPointerException
class java.lang.SecurityException
class java.lang.UnsupportedOperationException
-------------------
thanks in advance.
Unni
+Pie Number of slices to send: Send
do we need to know all unchecked exceptions by name, so that we don't worry about handling them?
No, you don't need to know *all* unchecked exceptions by name.
I understand checked exceptions should be declared or handled, and unchecked exception don't have to.
yup.
Or is it safe to assume the only unchecked exception (not Error) that will appear in the exam will be RuntimeException only?
do not assume that. You might get questions on errors as well. It is only to test that you know the concepts.
is it true to say all subclasses of RuntimeException are the only unchecked exceptions?..
Not the *only* unchecked exceptions. Subtypes of Error and RuntimeExceptions are unchecked exceptions.
Have a look at this post:
https://coderanch.com/t/242534/java-programmer-SCJP/certification/Overriding-methods-Exceptions
+Pie Number of slices to send: Send
Andres,
Thanks for your reply. The explanation and link was helpful.
I think Errors might be easy to identify in the exam since all the Error names ends with the word "Error" in it. So that I know, it is an unchecked and don't need to handle. (I realise Errors are different. they are always unchecked. They extend Throwable, not Exception).
Since RuntimeException (and its subclasses) are subclasses of Exception, I should be able to identify whether the thrown exception need to handled or not. For example:

With above code, compilor does not complain on exception-1 because it is a subclass of RuntimeException, where as compiler forces you to handle (or declare) exception-2 because it is NOT a subclass of RuntimeException, but at the same it is a subclass of Exception.
BUT, going back to my original question, given a scenario where similar question like the above comes up in exam, I should be able distinguish the subclasses of RuntimeException...so that I know it need not be handled ?
+Pie Number of slices to send: Send
Do not try to learn them by heart if you do not recognize them now. By the time of taking the exam you will know most of them. From now just pay attention to the exceptions are coming up as you study.
machines help you to do more, but experience less. Experience this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 640 times.
Similar Threads
Why this is a checked exception?
Checked and Unchecked Exceptions
Why this exception handling works?
Question on Exceptions
Java Handeling Exceptions
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 08:52:01.