This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "JavaCaps Mock #2 Q60 on exceptions" Watch "JavaCaps Mock #2 Q60 on exceptions" New topic
Author

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 {
throwMethod();
} 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...
 
Don't get me started about those stupid light bulbs.
 
subject: JavaCaps Mock #2 Q60 on exceptions
 
Similar Threads
Exception doubt
exception problem
throw an Exception....
Exception Q?
Exception