- 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 programming
Exception propagation refers to flows of exception from one catch block to other. Following are the rules −
If an exception occurs in the protected code, the exception is thrown to the first catch block in the list.
If the data type of the exception thrown matches ExceptionType1, it gets caught there.
If not, the exception passes down to the second catch statement.
This continues until the exception either is caught or falls through all catches.
At end case the current method stops execution and the exception is thrown down to the previous method on the call stack, this process is known as exception propagation.
Example
public class Tester { public static void main(String args[]) { int a,b; try { a = Integer.parseInt(args[0]); b = Integer.parseInt(args[1]); int c = a/b; System.out.println(c); } catch(ArrayIndexOutOfBoundsException ex) { System.out.println("Please pass the args while running the program"); } catch(NumberFormatException e) { System.out.println("String cannot be converted as integer"); } catch(ArithmeticException e1) { System.out.println("Division by zero is impossible"); }finally { System.out.println("The program is terminated"); } } }
Output
Please pass the args while running the program The program is terminated
- Related Articles
- Exception propagation in Java
- What is exception propagation in Java?
- Exception Propagation in C#
- Null Pointer Exception in Java Programming
- Exception chaining in Java
- Chained exception in Java\n
- Programming in Java.
- How to create a user defined exception (custom exception) in java?
- Exception Handling in C++ vs Java
- Stack in Java Programming
- Literals in Java programming
- Overloading in java programming
- Overriding in Java programming
- 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?

Advertisements