aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes JavaCaps Mock #2 Q60 on 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 "JavaCaps Mock #2 Q60 on exceptions" Watch "JavaCaps Mock #2 Q60 on exceptions" New topic

JavaCaps Mock #2 Q60 on exceptions

Larry Lecomte
Ranch Hand

Joined: Jun 14, 2002
Posts: 37
public class ThrowsDemo {
static void throwMethod() throws Exception {
System.out.println("Inside throwMethod.");
throw new IllegalAccessException("demo");
public static void main(String args[]) {
try {
} catch (IllegalAccessException e) {
System.out.println("Caught " + e);

A) Compilation error
B) Runtime error
C) Compile successfully, nothing is printed.
D) inside throwMethod. followed by caught: java.lang.IllegalAccessException: demo
Answer is: A
But in JLS�11.2 it says:
For each checked exception which is a possible result, the throws clause for the method (�8.4.4) or constructor (�8.8.4) must mention the class of that exception or one of the superclasses of the class of that exception.
Isn't Exception a superclass of IllegalAccessException
Larry Lecomte
Ranch Hand

Joined: Jun 14, 2002
Posts: 37
OK, I found that the catch clause must declare
that it catches objects of type Exception because of the declaration of throwMethod. The problem was NOT in the throwMethod...
It is sorta covered in the JavaRanch Style Guide.
subject: JavaCaps Mock #2 Q60 on exceptions