title: catch custom Exception in Apache Spark
body: <p>I have a problem to catch custom exceptions in Apache Spark.</p>
  
  <p>When I am doing a validation on a dataset in a foreach loop like this</p>
  
  <pre><code>ds.foreach(
          entry=&gt; {
            validate(entry)
          })
  </code></pre>
  
  <p>The validate function throws a Custom Exception when the entry is not valid.</p>
  
  <p>But in the catch block I am not able to catch my custom exception only a SparkException is thrown and can be  catched:</p>
  
  <pre><code>case customException : CustomException =&gt;
      //is never catched
  case exception : SparkException =&gt;
      //can be catched
  </code></pre>
  
  <p>How can I deal with that? I need to catch different sort of exceptions which are all thrown by the validate method. One way is to read the message of the SparkException which contains the origin exception but this is probably not a nice design.</p>
  
  <p>Any ideas?</p>