Write custom unchecked exception and trigger StackOverflow
Filed under Amazon
Free read 3 of 3Create 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
Create a class extending RuntimeException and provide standard constructors.
Write a recursive method without a base case that continuously calls itself.
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.