wood burning stoves*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Unchecked exceptions 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 "Unchecked exceptions" Watch "Unchecked exceptions" New topic
Author

Unchecked exceptions

Unni Kainila
Ranch Hand

Joined: Jul 26, 2003
Posts: 45
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
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
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:
http://www.coderanch.com/t/242534/java-programmer-SCJP/certification/Overriding-methods-Exceptions


I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
Unni Kainila
Ranch Hand

Joined: Jul 26, 2003
Posts: 45
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 ?
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
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.


SCJP2. Please Indent your code using UBB Code
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unchecked exceptions