1/31/2020 Java Nested try block example - javatpoint
Java Nested try block
The try block within a try block is known as nested try block in java.
Why use nested try block
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)
{
}
....
Java nested try example
https://www.javatpoint.com/nested-try-block 1/5
1/31/2020 Java Nested try block example - javatpoint
Let's see a simple example of java 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..");
}
}
← prev next →
Help Others, Please Share
Join Javatpoint Test Series
Placement AMCAT Bank PO/Clerk GATE
Papers eLitmas UPSSSC NEET
TCS Java Government CAT
HCL Python Exams Railway
Infosys C ProgrammingSSC CTET
IBM Networking Civil Services IIT JEE
https://www.javatpoint.com/nested-try-block 2/5
1/31/2020 Java Nested try block example - javatpoint
Accenture SBI
Learn Latest Tutorials
Ansible Mockito Talend
Tutorial Tutorial Tutorial
Ansible Mockito Talend
Microsoft Sharepoint Powershell
Azure Tutorial Tutorial Tutorial
Azure SharePoint Powershell
Kali Linux OpenCV Kafka
Tutorial Tutorial Tutorial
Kali Linux OpenCV Kafka
Pandas Joomla
Tutorial Tutorial Reinforcement
Learning
Pandas Joomla Tutorial
Reinforcement
Preparation
Aptitude Logical Verbal
Reasoning Ability
Aptitude
Reasoning Verbal A.
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
Artificial AWS Selenium
Intelligence Tutorial tutorial
Tutorial
AWS Selenium
AI
Cloud Hadoop ReactJS
tutorial tutorial Tutorial
Cloud Hadoop ReactJS
Data Science Angular 7 Blockchain
Tutorial Tutorial Tutorial
D. Science Angular 7 Blockchain
Git Tutorial Machine DevOps
Learning Tutorial
Git Tutorial
DevOps
ML
B.Tech / MCA
DBMS Data DAA
tutorial Structures tutorial
tutorial
DBMS DAA
DS
Operating Computer Compiler
System tutorial Network Design tutorial
tutorial
OS Compiler D.
C. Network
https://www.javatpoint.com/nested-try-block 4/5
1/31/2020 Java Nested try block example - javatpoint
Computer Discrete Ethical
Organization Mathematics Hacking
and Tutorial Tutorial
Architecture
D. Math. E. Hacking
COA
Computer Software html tutorial
Graphics Engineering
Tutorial Tutorial Web Tech.
C. Graphics Software E.
Cyber Automata C Language
Security Tutorial tutorial
tutorial
Automata C
Cyber Sec.
C++ tutorial Java tutorial .Net
Framework
C++ Java tutorial
.Net
Python List of Control
tutorial Programs Systems
tutorial
Python Programs
Control S.
Data Mining
Tutorial
Data Mining
https://www.javatpoint.com/nested-try-block 5/5