---
title: "What is exception propagation ?"  
description: "What is exception propagation ?"  
author: "Anonymous User"  
published: 2015-04-24  
updated: 2020-09-22  
canonical: https://www.mindstick.com/interview/2433/what-is-exception-propagation  
category: "java"  
tags: ["exception handling", "java"]  
reading_time: 2 minutes  

---

# What is exception propagation ?

Forwarding the exception object to the invoking method is known as exception propagation.\
An exception is first thrown from the top of the stack and if it is not caught, it drops down the call stack to the previous method,If not caught there, the exception again drops down to the previous method, and so on until they are caught or until they reach the very bottom of the call stack.This is called exception propagation.\
\
**Example:**\

```
class TestExceptionPropagation1{    void m(){      int data=50/0;    }    void n(){      m();    }    void p(){     try{      n();     }catch(Exception e){System.out.println("exception handled");}    }    public static void main(String args[]){     TestExceptionPropagation1 obj=new TestExceptionPropagation1();     obj.p();     System.out.println("normal flow...");    }  } 
```

\
**Output:**exception handled normal flow...\
Here exception occurs in m() method where it is not handled,so it is propagated to previous n() method where it is not handled, again it is propagated to p() method where exception is handled.\
Exception can be handled in any method in call stack either in main() method,p() method,n() method or m() method.

## Answers

### Answer by Anonymous User

Forwarding the exception object to the invoking method is known as exception propagation.\
An exception is first thrown from the top of the stack and if it is not caught, it drops down the call stack to the previous method,If not caught there, the exception again drops down to the previous method, and so on until they are caught or until they reach the very bottom of the call stack.This is called exception propagation.\
\
**Example:**\

```
class TestExceptionPropagation1{    void m(){      int data=50/0;    }    void n(){      m();    }    void p(){     try{      n();     }catch(Exception e){System.out.println("exception handled");}    }    public static void main(String args[]){     TestExceptionPropagation1 obj=new TestExceptionPropagation1();     obj.p();     System.out.println("normal flow...");    }  } 
```

\
**Output:**exception handled normal flow...\
Here exception occurs in m() method where it is not handled,so it is propagated to previous n() method where it is not handled, again it is propagated to p() method where exception is handled.\
Exception can be handled in any method in call stack either in main() method,p() method,n() method or m() method.


---

Original Source: https://www.mindstick.com/interview/2433/what-is-exception-propagation

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
