KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
What is the best way of handling exceptions while iterating over a loop in Scala? For instance, if I had a convert() method that could throw an exception, I'd like to catch that exception, log it, and keep iterating. Is there a "scala" way to do this? Ideally, I'd like something like... val points: Seq[Point] = ... val convertedPoints: Seq[ConvertedPoint] = points.map( p => { try { p.convert() } catch { case ex: Exception => logger.error("Could not convert", ex) } }) You can't do the above code since it's not a direct mapping from one list to the other (you get back Seq[Any] as opposed to Seq[ConvertedPoint] ).
Tags (comma-separated)
Save Edits
Cancel