title: Uncaught Exception Handling in Spark
body: <p>I am working on a Java based Spark Streaming application which responds to messages that come through a Kafka topic. For each message, the application does some processing, and writes back the results to a different Kafka topic.</p>
  
  <p>Sometimes due to unexpected data related issues, the code that operates on RDDs might fail and throw an exception. When that happens, I would like to have a generic handler that could take necessary action and drop a message to an error topic. Right now, these exceptions are written in Spark's log by Spark itself.</p>
  
  <p>What is the best approach to do this, instead of writing try-catch blocks for every code block that work on RDDs?</p>