If I need to compute something but do some side effect before returning that value, is the correct idiom try
/finally
without catch
?
e.g.,
def calculateSemesterAverage() = {
import scala.io.Source
def csv = Source.fromFile("some-file-to-parse.csv")
try {
for {line <- csv.getLines()
if some_condition(line)
data <- some_parser(line)
}
yield data
} finally {
csv.close()
}
}