Skip to content

Instantly share code, notes, and snippets.

@AlexRogalskiy
Last active December 20, 2020 10:23
Show Gist options
  • Save AlexRogalskiy/01cd3058127ae54bf628141f9b46ff7a to your computer and use it in GitHub Desktop.
Save AlexRogalskiy/01cd3058127ae54bf628141f9b46ff7a to your computer and use it in GitHub Desktop.
Scala exception handling
import scala.util.control.Exception._
val numbersAsStrings = Seq("1", "2", "3", "4", "10", "N")
val ints = numbersAsStrings flatMap { catching(classOf[NumberFormatException]) opt _.toInt } filter { _ % 2 == 0 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment