When is try,catch block used

Showing Answers 1 - 1 of 1 Answers

swapna

  • Aug 25th, 2005
 

the code which has the probability of raising an exception is placed in the try block. 
the code for handling the situation when an exception occurs is placed in the catch block with the instance of the exception as the parameter. 
when an exception occurs the control is passed to catch block. 
 
example 
 
int a[5]; 
 
try() 

try to access a[7] 

catch(ArrayIndexOutOfBoundsException e) 

System.out.Println("Out of Bounds"); 

 

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions