下面的代碼拋出異常:嘗試捕捉環繞失敗的高階函數?
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 0 at line (s(0).toString,s(0).toString)
我想趕上這個例外,只是不斷的地圖功能到下一個項目。如何圍繞高階函數圍繞try/catch,以忽略任何異常並繼續其餘函數:groupBy & mapValues?
println(toIterate.toList.map(s => (s(0).toString,s(0).toString))
.groupBy(_._1)
.mapValues(_.map(_._2)))
我的主要目標是允許繼續執行即使IndexOutOfBounds異常被任意的字符串拋出elemens –
這完成同樣的事情,但通過識別將發生異常情況,並跳過它。 –