Bird
0
0

Why does this async method fail to catch exceptions?

medium📝 Debug Q7 of 15
Spring Boot - Async Processing
Why does this async method fail to catch exceptions?
@Async
public void runTask() {
  try {
    throw new IllegalStateException("Fail");
  } catch (Exception e) {
    System.out.println("Caught: " + e.getMessage());
  }
}
AExceptions are caught correctly; no failure occurs.
BThe exception is thrown outside the try block.
CAsync methods cannot have try-catch blocks.
DThe exception is swallowed by Spring async proxy before try-catch.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze try-catch inside async method

    The exception is thrown inside the try block and caught immediately in the catch block.
  2. Step 2: Confirm behavior

    Since the exception is handled inside the method, no failure occurs due to uncaught exceptions.
  3. Final Answer:

    Exceptions are caught correctly; no failure occurs. -> Option A
  4. Quick Check:

    Try-catch inside async method works normally [OK]
Quick Trick: Try-catch inside async methods catches exceptions normally [OK]
Common Mistakes:
  • Assuming async proxy swallows exceptions before try-catch
  • Thinking try-catch is disallowed in async methods
  • Believing exceptions propagate despite catch

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes