Exception Propagation in Java
Last Updated :
06 May, 2025
In Java, 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. After a method throws an exception, the runtime system attempts to find something to handle it. The set of possible "somethings" to handle the exception is the ordered list of methods that had been called to get to the method where the error occurred. The list of methods is known as the call stack, and the method of searching is Exception Propagation.
The image below demonstrates the flow of method calls in a program

Exception Propagation in Unchecked Exceptions
When an exception happens, propagation is a process in which the exception is dropped from the top to the bottom of the stack. If not caught once, the exception again drops down to the previous method, and so on until it gets caught or until it reaches the very bottom of the call stack. This is called exception propagation, and this happens in case of Unchecked Exceptions.
In the example below, an exception occurs in the m() method, where it is not handled, so it is propagated to the previous n() method, where it is not handled, again it is propagated to p() method, where the exception is handled. Exceptions can be handled in any method in the call stack, either in the main() method, p() method, n() method, or m() method.
Note: By default, unchecked exceptions are forwarded in the calling chain (propagated).
Example:
JAVA
// Java program to illustrate
// unchecked exception propagation
// without using throws keyword
class Geeks {
void m()
{
int data = 50 / 0; // unchecked exception occurred
// exception propagated to n()
}
void n()
{
m();
// exception propagated to p()
}
void p()
{
try {
n(); // exception handled
}
catch (Exception e) {
System.out.println("Exception handled");
}
}
public static void main(String args[])
{
Geeks obj = new Geeks();
obj.p();
System.out.println("Normal flow...");
}
}
OutputException handled
Normal flow...
Exception Propagation in Checked Exceptions
Unlike Unchecked Exceptions, the propagation of exception does not happen in case of Checked Exception and its mandatory to use throw keyword here. Only unchecked exceptions are propagated. Checked exceptions throw compilation error.
In example below, If we omit the throws keyword from the m() and n() functions, the compiler will generate compile time error this is because checked exceptions cannot propagate without the explicit use of the throws keyword.
Note: By default, checked exceptions are not forwarded in calling chain (propagated). They must be declared in the method signature using the throws keyword.
Example:
JAVA
// Java program to illustrate exception propagation
// in checked exceptions and it can be propagated
// by throws keyword ONLY
import java.io.IOException;
class Geeks {
// exception propagated to n()
void m() throws IOException
{
// checked exception occurred
throw new IOException("device error");
}
// exception propagated to p()
void n() throws IOException
{
m();
}
void p()
{
try {
// exception handled
n();
}
catch (Exception e) {
System.out.println("Exception handled");
}
}
public static void main(String args[])
{
Geeks obj = new Geeks();
obj.p();
System.out.println("normal flow...");
}
}
OutputException handled
normal flow...
Unchecked Exceptions vs Checked Exceptions
The table below demonstrates the difference between unchecked and checked exception.
Property | Unchecked Exceptions | Checked Exceptions |
---|
Propagation | Propagate automatically through the call stack. | Do not propagate automatically. |
---|
Throws Keyword | Do not require the throws keyword | It requires a throw keyword |
---|
Compile-Time Check | Not checked at compile-time | Checked at compile-time, |
---|
Example | ArithmeticException, NullPointerException, IndexOutOfBoundsException. | IOException, SQLException |
---|
Similar Reads
Null Pointer Exception in Java
A NullPointerException in Java is a RuntimeException. In Java, a special null value can be assigned to an object reference. NullPointerException is thrown when a program attempts to use an object reference that has the null value.Example:Java// Demonstration of NullPointerException in Java public cl
5 min read
Best Practices to Handle Exceptions in Java
Exception Handling is a critical aspect of Java programming, and following best practices for exception handling becomes even more important at the industry level, where software is expected to be highly reliable, maintainable, and scalable. In this article, we will discuss some of the best practice
7 min read
Spring MVC - Exception Handling
Prerequisites: Spring MVC When something goes wrong with your application, the server displays an exception page defining the type of exception, the server-generated exception page is not user-friendly. Spring MVC provides exception handling for your web application to make sure you are sending your
6 min read
Java Exception Handling
Exception handling in Java allows developers to manage runtime errors effectively by using mechanisms like try-catch block, finally block, throwing Exceptions, Custom Exception handling, etc.An Exception is an unwanted or unexpected event that occurs during the execution of a program (i.e., at runti
10 min read
Top 5 Exceptions in Java with Examples
An unexpected unwanted event that disturbs the program's normal execution after getting compiled while running is called an exception. In order to deal with such abrupt execution of the program, exception handling is the expected termination of the program. Illustration: Considering a real-life exa
5 min read
Errors V/s Exceptions In Java
In Java, errors and exceptions are both types of throwable objects, but they represent different types of problems that can occur during the execution of a program. Errors are usually caused by serious problems that are outside the control of the program, such as running out of memory or a system cr
5 min read
Chained Exceptions in Java
Chained Exceptions in Java allow associating one exception with another, i.e. one exception describes the cause of another exception. For example, consider a situation in which a method throws an ArithmeticException because of an attempt to divide by zero, but the root cause of the error was an I/O
3 min read
Output of Java program | Set 12(Exception Handling)
Prerequisites : Exception handling , control flow in try-catch-finally 1) What is the output of the following program? Java public class Test { public static void main(String[] args) { try { System.out.printf("1"); int sum = 9 / 0; System.out.printf("2"); } catch(ArithmeticExcept
3 min read
Types of Exception in Java with Examples
Java defines several types of exceptions that relate to its various class libraries. Java also allows users to define their own exceptions. Built-in Exceptions: Built-in exceptions are the exceptions that are available in Java libraries. These exceptions are suitable to explain certain error situati
8 min read
ArrayStoreException in Java
ArrayStoreException in Java occurs whenever an attempt is made to store the wrong type of object into an array of objects. The ArrayStoreException is a class which extends RuntimeException, which means that it is an exception thrown at the runtime. Class Hierarchy: java.lang.Object ↳ java.lang
2 min read