Home Help Java T try Java Keyword

Related Tutorials


 
 

Share on Google+Share on Google+

try Java Keyword

Advertisement
The try is a keyword defined in the java programming language.

try Java Keyword

     

The try is a keyword defined in the java programming language. Keywords are basically reserved words which have specific meaning relevant to a compiler in java programming language likewise the try keyword indicates the following :

-- The try keyword in java programming language is used to wrap the code in a block of statements where there are chances to get some erroneous condition in form of  an exception object.
-- Every try block in java programming language must be followed by a one catch or finally clause at least.
-- In exception handling mechanism,
if an exception class is not handled by any catch block, then that exception propagates up the call stack till it catches the exception else it prints an appropriate error message.

Example to use the try blocks: 

try{
<block of code that may throw exceptions>
}
catch (<java.lang.Exception or subclass> e){
<code_to_handle_exception e>
}

 

try{
<block that may throw different exceptions>
}

catch (Exception1 e){
<code to handle Exception1 e>
}
catch (Exception2 e){
<code to handle Exception2 e>
}

 

try{
<block that may throw exceptions>
}

catch (<java.lang.Exception or subclass> e){
<code to handle exception e>
}

finally{
<statements needed to execute>
}

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 18, 2009

Related Tutorials

Discuss: try Java Keyword  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com