Module: | Classes, Objects, OOPs & Inheritance
Q47: Consider the following statements regarding the throws keyword in Java:
1. The throws keyword is appended to a method's signature to explicitly declare that the method might throw one or more specific exceptions during its execution.
2. If a method declares a checked exception using the throws keyword, any external method calling it is legally obligated by the compiler to either catch the exception or re-declare it in its own signature.
3. The throws keyword completely handles and resolves the exception internally within the method, strictly preventing it from propagating up the method call stack to the main thread.
Which of the above statements is/are correct?
2. If a method declares a checked exception using the throws keyword, any external method calling it is legally obligated by the compiler to either catch the exception or re-declare it in its own signature.
3. The throws keyword completely handles and resolves the exception internally within the method, strictly preventing it from propagating up the method call stack to the main thread.
Which of the above statements is/are correct?
✅ Correct Answer: A
🎯 Quick Answer:
The correct combination is 1 and 2. Statement 3 is incorrect because the throws keyword does absolutely nothing to handle or resolve an exception; its entire architectural purpose is to evade handling by delegating the responsibility (and propagating the error) up the call stack to the method that invoked it.It alerts any developer using the method that hazardous operations occur within, shifting the burden of safety compliance to the caller.
Structural Breakdown: The syntax is 'public void readFile() throws IOException, SQLException {}'. It strictly belongs on the method signature line, never inside the method body.
Historical/Related Context: This mechanism enforces "Duck Typing" for errors.
If a low-level utility method reads a file, it shouldn't be responsible for deciding how the application reacts to a missing file (should it show a popup? should it crash?). By using throws, the utility method passes the error up to the UI layer, which has the correct context to decide the outcome.
Causal Reasoning: If the caller method refuses to wrap the risky invocation in a try-catch block, the compiler forces the caller to also add the throws keyword to its own signature.
This chain continues upward until it hits the main() method.
If main() throws it, the JVM catches it, prints the stack trace, and violently terminates the application.