wood burning stoves*
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exceptions " Watch "Exceptions " New topic


Chris Judd

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,

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"; }
// 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

Joined: Feb 25, 2007
Posts: 23
Thanks Keith!
I agree. Here's the link: http://aspose.com/file-tools
subject: Exceptions
Similar Threads
mock question about exceptions...from K&B SCJP book
Question about Exceptions
Exceptions doubt
K&B question - overriding methods
K&S Chapter 5 q-3