Java Nested Try Block Example
Java Nested Try Block Example
Sometimes a situation may arise where a part of a block may cause one
error and the entire block itself may cause another error. In such cases,
exception handlers have to be nested.
Syntax:
....
try
{
statement 1;
statement 2;
try
{
statement 1;
statement 2;
}
catch(Exception e)
{
}
}
catch(Exception e)
{
}
....
https://www.javatpoint.com/nested-try-block 1/5
1/31/2020 Java Nested try block example - javatpoint
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..");
}
}
← prev next →
Accenture SBI
Pandas Joomla
Tutorial Tutorial Reinforcement
Learning
Pandas Joomla Tutorial
Reinforcement
Preparation
Interview Company
Questions Interview
Questions
https://www.javatpoint.com/nested-try-block 3/5
1/31/2020 Java Nested try block example - javatpoint
Interview Company
Trending Technologies
B.Tech / MCA
https://www.javatpoint.com/nested-try-block 4/5
1/31/2020 Java Nested try block example - javatpoint
C. Graphics Software E.
.Net
Data Mining
Tutorial
Data Mining
https://www.javatpoint.com/nested-try-block 5/5