មេរៀនទី៤៩: Nested try block

try block ជាមួយ try block គឺដឹងដូចជា nested try block។
ហេតុអ្វីបានប្រើ nested try block?
ជួនពេលខ្លះ ស្ថានការណ៍ កើតឡើងផ្នែកមួយនៃ block អាចបណ្តាល error និង block ទាំងមូល វាអាច បណ្តាលអោយ error ផ្សេងទៀត។
Syntax:
….
try
{
statement 1;
statement 2;
try
{
statement 1;
statement 2;
}
catch(Exception e)
{
}
}
catch(Exception e)
{
}
….
ឧទាហរណ៍នៃ  nested try block
class Excep6{
public static void main(String args[]){
try{
try{
System.out.println(“going to divide”);
int b =39/0;
}catch(ArithmeticException e){System.out.println(e);}
try{
int a[]=new int[5];
a[5]=4;
}catch(ArrayIndexOutOfBoundsException e){System.out.println(e);}
System.out.println(“other statement);
}catch(Exception e){System.out.println(“handeled”);}
System.out.println(“normal flow..”);
}
}