What is the difference between throw and throws in Java?
`throw` and `throws` are both part of Java's exception mechanism but operate at different points and serve different purposes.
`throw` is a statement used inside a method body to explicitly raise an exception. It takes an instance of `Throwable` (typically an `Exception` or `RuntimeException` subclass). Execution immediately leaves the current block and the stack unwinds looking for a matching `catch`. Example: `throw new IllegalArgumentException("value must be positive");`
`throws` is a clause in a method signature that declares which checked exceptions the method might propagate to its callers. It is a contract declaration, not an execution command. Any caller must either catch those exceptions or declare them in its own `throws` clause, propagating the obligation up the call stack. Example: `public void readFile(String path) throws IOException, ParseException {}`
The relationship: if a method uses `throw` to raise a checked exception, it must either handle that exception internally with `try-catch` or declare it with `throws`. Unchecked exceptions (`RuntimeException` subclasses) and errors can be thrown without a `throws` declaration.
Key distinctions: - `throw` operates at runtime; `throws` is a compile-time declaration. - `throw` takes a single object instance; `throws` lists one or more exception types (comma-separated). - `throw` causes program flow to change; `throws` is informational — it doesn't cause anything to happen on its own.
A well-designed API uses checked exceptions (declared with `throws`) for recoverable conditions callers are expected to handle, and unchecked exceptions for programming errors. Overusing checked exceptions forces callers into boilerplate handling that often just wraps and rethrows, which is a design smell.
| Aspect | throw | throws |
|---|---|---|
| Type | Statement | Method declaration keyword |
| Used in | Method/constructor body | Method/constructor signature |
| Takes | A Throwable instance | One or more exception class names |
| Purpose | Raises an exception at runtime | Declares possible checked exceptions to callers |
| Required for | Any exception you want to raise | Checked exceptions that aren't caught internally |
| Affects control flow | Yes — immediately | No — purely declarative |
Correctly distinguishes throw (raises exception) from throws (declares exceptions) with an accurate example of each.
Also explains checked vs unchecked exception rules, why throws is not required for RuntimeException, and the API design guidance for when to use checked vs unchecked exceptions.
Reading the answer is step one. Explaining it unprompted — under interview pressure — is what actually matters. Get AI-graded feedback on your answer with follow-up probes on your weak points.
Get Graded — Free Assessment