// // program to sum integers from file, with simple handling of errors // import scala.io.StdIn._ // "try" this code, going to "catch" if there is an error try { println("enter name of file containing ints") val filename = readLine val src = scala.io.Source.fromFile(filename) val lines = src.getLines.toList src.close val sum = lines.map(_.toInt).sum println("sum = " + sum) } catch { // "catch" specific types of errors case fileError:java.io.FileNotFoundException => { println("could not open input file") println(fileError) } case nf:NumberFormatException => { println("non-integer input in file") println(nf) } }