- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Exception propagation in Java
Exception propagation in Java occurs when an exception thrown from the top of the stack. When it is not caught, the exception drops down the call stack of the preceding method. If it is not caught there, it further drops down to the previous method. This continues until the method reaches the bottom of the call stack or is caught somewhere in between.
Example
Let us see an example which illustrates exception propagation in Java −
public class Example { void method1() // generates an exception { int arr[] = {10,20,30}; System.out.println(arr[7]); } void method2() // doesn't catch the exception { method1(); } // method1 drops down the call stack void method3() // method3 catches the exception { try { method2(); } catch(ArrayIndexOutOfBoundsException ae) { System.out.println("Exception is caught"); } } public static void main(String args[]) { Example obj = new Example(); obj.method3(); } }
Output
The output is as follows −
Exception is caught
- Related Articles
- Exception propagation in Java programming
- What is exception propagation in Java?
- Exception Propagation in C#
- Exception chaining in Java
- Chained exception in Java\n
- How to create a user defined exception (custom exception) in java?
- Null Pointer Exception in Java Programming
- Exception Handling in C++ vs Java
- Is it possible to throw exception without using "throws Exception" in java?
- While chaining, can we throw unchecked exception from a checked exception in java?
- Exception handling with method overriding in Java.
- Out of memory exception in Java:\n
- Difference between Exception and Error in Java
- Difference Between Error and Exception in Java
- Importance of Proper Exception Handling in Java

Advertisements