0% found this document useful (0 votes)
20 views2 pages

4 Java Nested Try Block Example

The document explains the concept of nested try blocks in Java, where a try block is contained within another try block to handle multiple exceptions. It discusses the necessity of using nested try blocks when different parts of a block may cause different errors. An example is provided to illustrate how nested try blocks work in practice.

Uploaded by

Anima
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views2 pages

4 Java Nested Try Block Example

The document explains the concept of nested try blocks in Java, where a try block is contained within another try block to handle multiple exceptions. It discusses the necessity of using nested try blocks when different parts of a block may cause different errors. An example is provided to illustrate how nested try blocks work in practice.

Uploaded by

Anima
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

9/14/2015 Java Nested try block example - javatpoint

Content Menu ▼

Best Coding Program


Want to give your career a boost? Join the StackRoute program.

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


Let's see a simple example of java nested try block.

. class Excep6{
. public static void main(String args[]){
http://www.javatpoint.com/nested-try-block 1/2
9/14/2015 Java Nested try block example - javatpoint

. 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 →

http://www.javatpoint.com/nested-try-block 2/2

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy