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 NumberFormatException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "NumberFormatException" Watch "NumberFormatException" New topic
Author

NumberFormatException

m prabhu
Ranch Hand

Joined: Jan 29, 2008
Posts: 79
is it a checked or unchecked exception
Freddy Wong
Ranch Hand

Joined: Sep 11, 2006
Posts: 959

If I tell you the answer right away, it's not a good way to learn Do you know the difference between unchecked and checked exception? If you do, you should be able to answer your own question.


SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
My Blog
m prabhu
Ranch Hand

Joined: Jan 29, 2008
Posts: 79
as per my understanding it is a checked exception.

and.. as per rules of overriding..
the overridding method should not throw new or broader exceptions.
hence i am confused with the below question in k&B book excercise for chapter -5 qustion no.3..
only a & d should be correct.
but answer involves e&f also which throw new exception numberformatexception. thats my confusion.

------------
class Animal {
public void eat() throws Exception {
// throws an Exception
}
}
class Dog2 extends Animal {
public void eat() { // no Exceptions }
public static void main(String [] args) {
Animal a = new Dog2();
Dog2 d = new Dog2();
d.eat(); // ok
a.eat(); // compiler error -
// unreported exception
}
}
------------
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"; }
Answer:
�� 3 A, D, E, and F are correct. It���s okay for an overriding method to throw the same
exceptions, narrower exceptions, or no exceptions. And it���s okay for the overriding
method to throw any runtime exceptions.
���� B is incorrect, because the overriding method is trying to throw a broader exception.
C is incorrect. This method doesn���t override, so the output is a. (Objective 2.4)
Freddy Wong
Ranch Hand

Joined: Sep 11, 2006
Posts: 959

NumberFormatException is a RuntimeException (unchecked exception) and for overriding method, you're allowed to throw any RuntimeException. Thus E and F are correct.
m prabhu
Ranch Hand

Joined: Jan 29, 2008
Posts: 79
yes.i checked in API.its a runtime exception.

what i thougt is
JVM thrown == runtime exception (unchecked)
Programatically thrown = compile time(checked)

hence my understanding is wrong.

so please tell me how to differentiate between runtime and compile time exceptions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NumberFormatException