Bird
0
0

Identify the error in this Kafka Streams error handling code:

medium📝 Debug Q14 of 15
Kafka - Advanced Stream Processing
Identify the error in this Kafka Streams error handling code:
streams.foreach((key, value) -> {
  try {
    process(value);
  } catch Exception e {
    log.error(e.getMessage());
  }
});
AMissing parentheses around Exception e in catch block
BUsing foreach instead of map for error handling
CLogging error message is incorrect
DTry block should be outside the foreach
Step-by-Step Solution
Solution:
  1. Step 1: Check catch block syntax

    In Java, catch must have parentheses around the exception type and variable.
  2. Step 2: Identify missing parentheses

    The code has 'catch Exception e' missing parentheses; correct is 'catch (Exception e)'.
  3. Final Answer:

    Missing parentheses around Exception e in catch block -> Option A
  4. Quick Check:

    Catch syntax requires parentheses [OK]
Quick Trick: Catch blocks always need parentheses around exception [OK]
Common Mistakes:
  • Omitting parentheses in catch
  • Confusing foreach and map usage
  • Thinking logging method is wrong

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes