Win a copy of Building Blockchain Apps this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Parsing Problem

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator











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.
 
Harshit Sethi
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Who said you that programmers cannot throw Runtime Exceptions .

Cannot you say new RuntimeException();
 
Harshit Sethi
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Harshit Sethi
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does Somebody have a list of Exceptions classifying the checked and unchecked exceptions that are in syllaybus of SCJP ???
 
Sahil Kapoor
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, i will post a list of checked and unchecked exceptions by evening....

 
Harshit Sethi
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay Sahil ,my doubt is clear now.But help me for the list of Exceptions.
 
Harshit Sethi
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post it here.
 
Prateek Rawal
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Prateek,it was really helpful information.
 
Harshit Sethi
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
If you look closely at this tiny ad, you will see five bicycles and a naked woman:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!