title: Catch Exception in Futures
body: <p>I have a spark application wrote in scala using futures. So until yesterday, I didn't have any try/catch inside the future but I need to add. Before try/catch, any errors inside the future stopped the spark application and this is the behavior that I want, but after try/catch the application completes without any error.</p>
  <p>This is my main object:</p>
  <pre><code>object TableProcessorWrapper extends SparkSessionWrapper {
  
    def main(args: Array[String]): List[Unit] = {
  
      implicit val ec = ExecutionContext.fromExecutor(new java.util.concurrent.ForkJoinPool(4))
  
      val dynamodb = DynamodbOperations()
  
      val tables = dynamodb.getTablesToProcess(args(0), &quot;tabela&quot;)
  
      val processors = for {
        table &lt;- tables
      } yield Future {
        TableProcessor(table).start(spark)
      }
  
      Await.result(Future.sequence(processors), Duration.Inf)
    }
  }
  
  </code></pre>
  <p>This is a part of the code inside the future:</p>
  <pre><code>class TableProcessor(
      fileReader: FileReader,
      tableProcessorConfig: TableProcessorConfig,
      transformers: Seq[BaseTransformer],
      anonymization: AnonymizationBase,
      schemaConverter: SchemaConverter,
      logAnalytics: LogAnalytics
  ) {
  
    def start(spark: SparkSession): Unit = {
  
  
  try {
  
  CODE HERE
  
  } catch {
          case e: Exception =&gt;
            logAnalyticsWithFiles.stopProcessing().failedProcessing().writeLog()
            throw new Exception(e)
        }
  
  </code></pre>
  <p>What I am doing wrong?</p>