Bird
Raised Fist0

Given this snippet, what will be printed if send() throws a SerializationException?

medium📝 Predict Output Q5 of Q15
Kafka - with Java/Python
Given this snippet, what will be printed if send() throws a SerializationException? try { producer.send(record).get(); System.out.println("Message sent"); } catch (Exception e) { System.out.println("Error: " + e.getClass().getSimpleName()); }
ANo output, program crashes
BMessage sent
CError: Exception
DError: SerializationException
Step-by-Step Solution
Solution:
  1. Step 1: Recall KafkaProducer send serialization behavior

    producer.send(record) serializes the record synchronously; SerializationException throws directly from send(), before .get().
  2. Step 2: Trace exception handling

    SerializationException is caught by catch(Exception e), printing "Error: SerializationException".
  3. Final Answer:

    Error: SerializationException -> Option D
  4. Quick Check:

    SerializationException from send() caught directly, prints class name [OK]
Quick Trick: SerializationException throws synchronously from send(), caught directly [OK]
Common Mistakes:
MISTAKES
  • Thinking serialization errors are asynchronous via .get()
  • Expecting program crash without output
  • Believing "Message sent" prints on exception

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes