Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exceptiopn handling

 
Smitha Prasad
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
during exception ahndling is it required to handle it? i.e must it be caught? And what is the difference in using checked exceptions and normal exceptions?
 
Smitha Prasad
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the difference in using throw and try?
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
These are very basic questions. You can either search this forum or check out the Java tutorial at Sun's site. OTOH, any descent textbook should have them explained.
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"try" means "check out the following piece of code" and if it has a problem find the appropriate catch block and follow those instructions." You will know if it had a problem, because it will throw an exception if it does.
"throw" means "a problem has been found and I am going to deal with it by creating an exception object that explains the whole thing and throwing it to the class that called me and hope that that class that has a better idea of what to do with this - since I don't have any good advice". Of course as a rule you end up catching an exception that a lower level class has thrown to you and you have to decide what to do about it.
If your class DOES have some good advice, then it can handle the exception itself by catching the exception and dealing with it - or it can deal with it by re-throwing it (hopefully with a better message or whatever).
 
Saif Ullah
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The difference between checked and unchecked exceptions is that, in case of checkecked exceptions you have to either handle them or leave the handling explicitly to the caller.
In case of unchecked exceptions, these exceptions has been implicitly handled by the default Exception Handler of the JVM, that is why the programmer is not required to handle them explicitly.
with regards

A java Student
saif ullah
 
Smitha Prasad
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks cindy and saif
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic