← Amazon questions

Write custom unchecked exception and trigger StackOverflow

Filed under Amazon

Free read 3 of 3

Create a class extending RuntimeException and provide standard constructors.

The question

Write the implementation for a custom unchecked exception in Java, and write a small program snippet that will trigger a StackOverflowError.

Constraints

  • Custom exception must extend RuntimeException.
  • Recursion triggering StackOverflowError must lack a proper base case.

Approach

  1. Create a class extending RuntimeException and provide standard constructors.

Tips

  • What they are testing: Ensure custom exception has appropriate constructors (default and message-based).
  • Common mistake: Extending Exception instead of RuntimeException for an unchecked exception.

Related Amazon questions

Collected from public candidate posts and coding forums. Updated Nov 2026.