What is the difference between throw and throws in Java?
A specific syntax question distinguishing between the keyword used to raise an exception and the clause used to declare it.
Why Interviewers Ask This
This tests precise knowledge of Java syntax and the flow of exception propagation. Confusion here indicates a lack of deep understanding of how exceptions move through the call stack.
How to Answer This Question
Clearly state that 'throw' is used inside a method to explicitly raise an exception. 'Throws' is used in the method signature to declare that a method might throw an exception, forcing callers to handle it. Provide a small code snippet example if possible.
Key Points to Cover
- Throw raises exception
- Throws declares possibility
- Method signature usage
- Propagation flow
Sample Answer
The 'throw' keyword is used within a method body to manually trigger an exception object, halting normal execution. Conversely, 'throws' appears in the method declaration to specify which exceptions a method might propag…
Common Mistakes to Avoid
- Using keywords interchangeably
- Confusing placement
- Not understanding propagation
Sound confident on this question in 5 minutes
Answer once and get a 30-second AI critique of your structure, content, and delivery. First attempt is free — no signup needed.