- 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
What is exception propagation in Java?
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, in which 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
Here is code segment showing how to use multiple try/catch
statements. class ExceptionPropogation { 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
- Exception propagation in Java programming
- Exception Propagation in C#
- What is Tuple ID Propagation?
- What is rectilinear propagation of light?
- What is Exception in Python?
- Is it possible to throw exception without using "throws Exception" in java?
- What is null pointer exception in Java and how to fix it?
- What happens if an exception is not handled in a java program?
- Exception chaining in Java
- What is exception handling in Python?
- What is exception handling in C#?
- What is Exception Handling in PHP ?
- Is it possible to create a custom exception in java without extending Exception class?
- What is Sequential Exception Technique?

Advertisements