Exception Propagation in Java: Explanation & Practice

Understand exception propagation through call stack

Problem summary

Create a chain of method calls and observe how exceptions propagate.

Starter code

public class Main {
    // method1 calls method2 calls method3
    // method3 throws exception
    // Handle at appropriate level
    
    public static void main(String[] args) {
        // Call method1
    }
}

Expected output and test cases

  • Propagation path
    Entering method1
    Entering method2
    Entering method3
    Exception in method3
    Handled in method1
  • Early exception
    Entering method1
    Handled in method1
  • No exception
    Entering method1
    Entering method2
    Entering method3
    Success

Hints

  1. Exceptions propagate up call stack
  2. Handle where appropriate
  3. Log entry/exit for tracing

Related Exception Handling exercises

Practice all Exception Handling exercises · Run this idea in the Java compiler