my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Parsing Problem 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 "Parsing Problem" Watch "Parsing Problem" New topic
Author

Parsing Problem

Harshit Sethi
Ranch Hand

Joined: Jul 16, 2010
Posts: 75











The two codes shown above are using parse() and parseXXX() methods. parse() method throws ParseException and parseXXX() method throws IllegalArgumentException.Both the Exceptions are checked Exception.But the first program runs without try/catch and the second one is giving a compiler error.

Please resolve this issue.
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

IllegalArgumentException is a RuntimeException

http://download.oracle.com/docs/cd/E17476_01/javase/1.4.2/docs/api/java/lang/IllegalArgumentException.html


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Harshit Sethi
Ranch Hand

Joined: Jul 16, 2010
Posts: 75
Turn to page number 382 of Kathy Sierra if you have it,It is shown that it is thrown programmatically that is it is a checked Exception
Sahil Kapoor
Ranch Hand

Joined: Sep 12, 2009
Posts: 316
Who said you that programmers cannot throw Runtime Exceptions .

Cannot you say new RuntimeException();


SCJP 6.0 96%

(Connecting the Dots ....)
Harshit Sethi
Ranch Hand

Joined: Jul 16, 2010
Posts: 75
Thats the way checked Exception is described in the book,and by saying programatically it means that is checked by the program and nothing else.
Prateek Rawal
Ranch Hand

Joined: Dec 19, 2009
Posts: 90
More precisely, parseInt() throws NumberFormatException( an indirect subclass of RuntimeException-an unchecked Exception)
Thus no try/catch required........(more precisely need not be handled or declared)

However parse() method of Date throws ParseException(a sublcass of Exception-a checked exception)
Thus it must be either handled or declared....or in your words try/catch required.....

PS: Thrown Programatically does not mean it is a checked exception, a programmatically thrown exception can be unchecked exception, like the one you saw now.....Remember, checked and unchecked exceptions are a different criteria of characterising exceptions and programmatically or by JVM is another criteria, don't mix them up.....and a suggestion, google it down if want to find out if an exception is checked or unchecked, and make notes of it.......

Happy SCJP


Waiting for enlightenment....
Harshit Sethi
Ranch Hand

Joined: Jul 16, 2010
Posts: 75
Does Somebody have a list of Exceptions classifying the checked and unchecked exceptions that are in syllaybus of SCJP ???
Sahil Kapoor
Ranch Hand

Joined: Sep 12, 2009
Posts: 316
Harshit Sethi wrote:Thats the way checked Exception is described in the book,and by saying programatically it means that is checked by the program and nothing else.


No

They said checked exceptions are those which are checked by compiler.

and

they said Programatic exceptions are those which are thrown by Programmers (you) or API writers.

You are perceiving wrong !!! They said it corectly without any chaos !!!
Prateek Rawal
Ranch Hand

Joined: Dec 19, 2009
Posts: 90
Okay, i will post a list of checked and unchecked exceptions by evening....

Harshit Sethi
Ranch Hand

Joined: Jul 16, 2010
Posts: 75
okay Sahil ,my doubt is clear now.But help me for the list of Exceptions.
Harshit Sethi
Ranch Hand

Joined: Jul 16, 2010
Posts: 75
Post it here.
Prateek Rawal
Ranch Hand

Joined: Dec 19, 2009
Posts: 90
Common Checked and Unchecked Exceptions:

1)Checked

- ClassNotFoundException, InstantiationException, illegaAccessException, NoSuchMethodException, IOException, EOFException, FileNotFoundException

2)Unchecked
- NullPointerException, NumberFormatException, ArithmeticException, ClassCastException, IllegalArgumentException, IllegalStateException, ArrayIndexOutOfBoundException, StringIndexOutOfBoundException, IndexOutOfBoundException, NegativeArraySizeException
Harshit Sethi
Ranch Hand

Joined: Jul 16, 2010
Posts: 75
Thanks Prateek,it was really helpful information.
Harshit Sethi
Ranch Hand

Joined: Jul 16, 2010
Posts: 75
I although want to add some more that are related to our chapters:

Checked:
InterruptedException
FileNotFoundException.
ClassNotFoundException
IOException.
EndOfFileException.

Unchecked:
IllegalMonitorStateException
IllegalThreadStateException
NotSerializableException
IllegalFormatConversionException
NullPointerException

Error:
ExceptionInInitializationError
AssertionError
OutOfMemoryError
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Parsing Problem
 
Similar Threads
What is the output and Why
Error Not Understand!!!
doubt in parsing
Date
Date Format related