Bird
Raised Fist0

Given this Java Kafka consumer code snippet, what will be printed if a network error occurs during poll?

medium📝 Predict Output Q13 of Q15
Kafka - with Java/Python
Given this Java Kafka consumer code snippet, what will be printed if a network error occurs during poll?
try {
  ConsumerRecords records = consumer.poll(Duration.ofMillis(100));
  for (var record : records) {
    System.out.println(record.value());
  }
} catch (WakeupException e) {
  System.out.println("Consumer interrupted");
} catch (Exception e) {
  System.out.println("Error during poll");
}
AError during poll
BConsumer interrupted
CNo output
DException stack trace
Step-by-Step Solution
Solution:
  1. Step 1: Identify exception types caught

    WakeupException prints "Consumer interrupted"; all other exceptions print "Error during poll".
  2. Step 2: Determine exception for network error

    Network errors throw general exceptions, not WakeupException.
  3. Final Answer:

    Error during poll -> Option A
  4. Quick Check:

    Network error triggers general Exception = Error during poll [OK]
Quick Trick: General exceptions print "Error during poll" [OK]
Common Mistakes:
MISTAKES
  • Confusing WakeupException with network errors
  • Expecting no output on error
  • Assuming stack trace prints automatically

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes