<div dir="ltr" style="text-align: justify;" trbidi="on">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.</p>
<p><b>Note: <i>By default Unchecked Exceptions are forwarded in calling chain (propagated)</i>.</b></p>
<pre class="highlight" name="code">class ExceptionPropagation{ 
 void m(){ 
 int data = 10/0; 
 } 
 void n(){ 
 m(); 
 } 
 void p(){ 
 try{ 
 n(); 
 }catch(Exception e){ 
 System.out.println("exception handled"); 
 } 
 } 
 public static void main(String args[]){ 
 ExceptionPropagation obj = new ExceptionPropagation(); 
 obj.p(); 
 System.out.println("normal flow..."); 
 } 
} 
</pre>
<div align='center' id="ads-id"></div>
<p><b>output here:</b></p>
<div class="separator" style="clear: both; text-align: center;"><img border="0" src="https://dineshonjava.com/wp-content/uploads/2013/04/propagationExc.png"/></div>
<p>
In the following figure show the stack presentation of the exception propagation flow.</p>
<div class="separator" style="clear: both; text-align: center;"><img border="0" src="https://dineshonjava.com/wp-content/uploads/2013/04/propagation.jpg"/></div>
<p>
In the above example 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.</p>
<p> Exception can be handled in any method in call stack either in main() method,p() method,n() method or m() method.</p>
<p><b>Note: <i>By default, Checked Exceptions are not forwarded in calling chain (propagated)</i>.</b></p>
<pre class="highlight" name="code">class ExceptionPropagation{ 
 void m(){ 
 throw new java.io.IOException("device error");//checked exception 
 } 
 void n(){ 
 m(); 
 } 
 void p(){ 
 try{ 
 n(); 
 }catch(Exception e){ 
 System.out.println("exception handeled"); 
 } 
 } 
 public static void main(String args[]){ 
 ExceptionPropagation obj = new ExceptionPropagation(); 
 obj.p(); 
 System.out.println("normal flow"); 
 } 
} 
</pre>
<p>
<b>In the above Program which describes that checked exceptions are not propagated.</b></p>
<div class="separator" style="clear: both; text-align: center;"><img border="0" height="119" src="https://dineshonjava.com/wp-content/uploads/2013/04/propagationExc1.png" width="600"/></div>
<p></p>
<div style="background-color: pink; border-width: thin; text-align: center;"><b><;<;<a href="https://dineshonjava.com/throws-keyword-in-java/">Previous</a> <;<; ; ; || <a href="https://dineshonjava.com/core-java-baby-step-to-be-best-java-ian/">Index </a>||  ; >;>;<a href="https://dineshonjava.com/handle-exceptions-in-overriding-methods/">Next</a> >;>;</b></div>
</div>
<div class="wp-post-navigation"> 
									 <div class="wp-post-navigation-pre"> 
									 <a href="https://dineshonjava.com/throws-keyword-in-java/">Previous</a> 
									 </div> 
									 <div class="wp-post-navigation-next"> 
									 <a href="https://dineshonjava.com/handle-exceptions-in-overriding-methods/">Next</a> 
									 </div> 
									</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
 $.post('https://dineshonjava.com/wp-admin/admin-ajax.php', {action: 'mts_view_count', id: '497'});
});
</script>
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…