Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unchecked exceptions

 
Unni Kainila
Ranch Hand
Posts: 45
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1561
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Unni Kainila
Ranch Hand
Posts: 45
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2120
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic