title: Try catch expression to catch ArrayIndexOutOfBoundsException in Scala
body: <p>I have a source file which has some bad data records, I want to handle <code>ArrayIndexOutofBoundsException</code> and increment my accumulator which is used to output bad data records.</p>
  
  <pre><code>val test = sourceFile.map(x =&gt; x.split("\\|")).
    filter(line =&gt; line(0).contains("1017")).map(x =&gt; {
      try {
        x.filter(line =&gt; {
          line.length &gt;= 37
        }).map(x =&gt; x(38))
      }
      catch {
        case x: ArrayIndexOutOfBoundsException =&gt; {
          println("Bad Data Found".format(x))
          Linecounter += 1
          None
        }
      }
    })
  
  test.count()
  test.saveAsTextFile(Quotepath)
  println("Bad Data Count %s:-".format(Linecounter))
  </code></pre>
  
  <p>Problem is I can't see accumulator output as count of records example 1 or etc .., can anyone help not sure whats wrong here.</p>