• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Exceptions in Dan's Topic Exams

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dan's topic exams on Exceptions had a few questions like I've attached below...
Kathy's book says we don't need to memorize the exception hierarchy....so can I assume there won't be such questions on the exam? And even if they are, I'll be given a hierarchy tree....is that right?
Question 1
1. class A {
2. void m1() {throw new IndexOutOfBoundsException();}
3. void m2() {throw new InstantiationException();}
4. void m3() {throw new IllegalAccessException();}
5. void m4() {throw new NullPointerException();}
6. void m5() {throw new NoSuchMethodException();}
7. void m6() {throw new SecurityException();}
8. }
What is the result of attempting to compile the program?
a. Compiler error at line 2.
b. Compiler error at line 3.
c. Compiler error at line 4.
d. Compiler error at line 5.
e. Compiler error at line 6.
f. Compiler error at line 7.
g. None of the Above
Answer 1
All of the exceptions in this question are a subclass of Exception and three are a subclass of RuntimeException. Any exception that is a subclass of RuntimeException should not be caught. Instead, it should be allowed to bubble to the top of the program where the runtime system will display a stack trace. RuntimeExceptions are a result of program bugs. A RuntimeException should not be listed in the throws clause of a program. Methods m1, m5, and m6 throw subclasses of Exception that are not subclasses of RuntimeException. Any Exception that is a direct subclass of Exception must either be caught or must be declared in the throws clause of the method.
 
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for using my exam.
Of course Kathy and Bert have a very detailed understanding of what is on the real exam. If they say that it is not necessary to memorize the exception hierarchy then we can all be sure that it must be true.
I'll upload a new version of the exam within the next month or so. The new version won't have any questions that require memorization of the exception hierarchy.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Monisha, but it's still a good learning experience to try and remember a few exceptions and know whether they are checked or unchecked.
NumberFormatException, InterruptedException you will almost certainly see in the SCJP2 exam. It's important to know their checkedness.
 
Monisha Talwar
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Dan and Barry.
Just to be on the safe side, I will learn atleast part of the hierarchy tree. Do you know of a good place I can a diagram of the hierarchy.
I found this on one of the search engines...would this be enough? [Hope this formats right...]
Throwable
Error
LinkageError
ClassCircularityError
ClassFormatError
ExceptionInInitializerError
IncompatibleClassChangeError
AbstractMethodError
IllegalAccessError
InstantiationError
NoSuchFieldError
NoSuchMethodError
NoClassDefFoundError
UnsatisfiedLinkError
VerifyError
VirtualMachineError
InternalError
OutOfMemoryError
StackOverflowError
UnknownError
ThreadDeath
Exception
ClassNotFoundException
CloneNotSupportedException
IllegalAccessException
InstantiationException
InterruptedException
RuntimeException
ArithmeticException
ArrayStoreException
ClassCastException
IllegalArgumentException
IllegalThreadStateException
NumberFormatException
IllegalMonitorStateException
IndexOutOfBoundsException
NegativeArraySizeException
NullPointerException
SecurityException
Monisha.
 
Monisha Talwar
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry the text of the hierarcy tree I copied has not formated correctly and is ugly to read.
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not enough, but too many
It is useful to remember that unchecked exceptions either represent programmer errors, or their possible point of throwing is too frequent to force them to be checked ones: if the programmer knew that an array access would fail; it would not place the expression within a try clause, but it would fix the program. Also, if every access to a member of an object could produce a checked NullPointerException, practically every method should catch or declare.
On the other hand, checked exceptions represent failures that are beyond control of programmer. For instance a disk or network one. Still it is possible to take action if they occur, via the catch-declare mechanism. IOExceptions are good examples.
Do not learn a long list, but the most immediate one:
Throwable, Error, Exception...
AWTException, ClassNotFoundException, CloneNotSupportedException, InterruptedException, IOException
RuntimeExcception...
ArithmeticException, ArrayStoreException, ClassCastException, ConcurrentModificationException, IllegalArgumentException, IllegalStateException, IndexOutOfBoundException, NegativeArraySizeException, NoSuchElementException, NullPointerException, UnsupportedOperationException
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
IMHO we can narrow it down further:
For the wrapper classes you'll need: NumberFormatException
For threads you'll need: InterruptedException
For arrays and Strings you'll need: IndexOutOfBoundsException
/ArrayIndexOutOfBoundsException
/StringIndexOutOfBoundsException
For assertions: AssertionError
Generally you may need: Exception and RuntimeException
Any others appearing in the current SCJP2 exam are likely to be bogus, that is, the problem will lie elsewhere.
[ March 31, 2003: Message edited by: Barry Gaunt ]
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Barry.
 
Monisha Talwar
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a ton Jose & Barry for your help.
Monisha.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic