• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
}
 
Author
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
     
    please buy this thing and then I get a fat cut of the action:
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic