Last Updated: 06 March, 2023
Java allows to write one try block inside another try block, which is known as a "nested try block."
A nested try block is used when 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 of nested try block
Example 1: Java nested try block
Output
10
20
30
Exception occured in the inner try block...
50
60
70
Code after outer try block...
Example 2: Java nested try block
Output
Dividing both numbers:
Exception occured in the outer try block...
Code after outer try block...
Example 3: Java nested try block
Output
Outer try block...
APPLE
MONGO
Exception occured in the outer try block...
After Outer try block...
That's all guys, hope this Java article is helpful for you.
Happy Learning... 😀
feedback@javabytechie.com