File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help wanted ! PLease explain what is try and catch use for .

 
Tom Salo
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As the topic said, Could anyone please explain what is try and catch in Java means please.
Also is that the catch always will be use after we use try ?
e.g
try
{
// Some code here
}
catch
{
// Some Code here
}
 
James Chegwidden
Author
Ranch Hand
Posts: 201
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try /catch is used to handle exceptions.

Try must always be in tandem with either a catch and/or a finally. It cannot be alone.
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try means "execute the following code. If there is a problem look in the associated catch blocks to see how to handle the problem"
Catch means "if this is the problem that you ran into, this is what you should do about it". Normally this includes formatting some sort of message to the user or the console.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I began to learn about Exceptions in Java, I read (and reread a few times):
  • The Exceptions section of Sun's Java Tutorial
  • Chapter 10 of Bruce Eckel's Thinking In Java book (available as a free download through BruceEckel.com)
  • Chapters 80 and 81 of Bradley Kjell's Introduction to Computer Science using Java
  • Good Luck.
     
    I agree. Here's the link: http://aspose.com/file-tools
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic