What is the best way (concisest, clearest, idiomatic) to catch a MatchError, when assigning values with pattern matching?
Example:
val a :: b :: Nil = List(1,2,3) // throws scala.MatchError
The best way I found so far:
val a :: b :: Nil = try {
val a1 :: b1 :: Nil = List(1,2,3)
List(a1, b1)
catch { case e:MatchError => // handle error here }
Is there an idiomatic way to do this?
Slightly improving on Kim’s solution:
If you could provide more information on how you might handle the error, we could provide you a better solution.