File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes 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 "Exceptions " Watch "Exceptions " New topic
Author

Exceptions

Chris Judd
Greenhorn

Joined: Feb 25, 2007
Posts: 23
I'm having a hard time understanding why E is considered a correct answer to this question. The book lists NumberFormatException as a Programmatically throw exeption. I thought that means that it is a checked exception...how can I tell what is a checked excption and what is an unchecked exception?

Thanks for your help,
Chris

From 400 Chapter 5: Flow Control, Exceptions, and Assertions of the K & B book:

import java.io.*;
class Master {
String doFileStuff() throws FileNotFoundException { return "a"; }
}
class Slave extends Master {
public static void main(String[] args) {
String s = null;
try { s = new Slave().doFileStuff();
} catch ( Exception x) {
s = "b"; }
System.out.println(s);
}
// insert code here
}

Which, inserted independently at // insert code here, will compile, and produce the output
b? (Choose all that apply.)
A. String doFileStuff() { return "b"; }
B. String doFileStuff() throws IOException { return "b"; }
C. String doFileStuff(int x) throws IOException { return "b"; }
D. String doFileStuff() throws FileNotFoundException { return "b"; }
E. String doFileStuff() throws NumberFormatException { return "b"; }
F. String doFileStuff() throws NumberFormatException,
FileNotFoundException { return "b"; }
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
An unchecked exception is either RuntimeException, Error, or one of their subclasses.

In this case, you are not required to list the classes in the throws clause of the overriden method in the throws clause of the overriding method.

Also you are allowed to add unchecked exception to the throws clause of the overridding method.
Chris Judd
Greenhorn

Joined: Feb 25, 2007
Posts: 23
Thanks Keith!
 
 
subject: Exceptions
 
Similar Threads
K&S Chapter 5 q-3
K&B question - overriding methods
mock question about exceptions...from K&B SCJP book
Exceptions doubt
Question about Exceptions