// // program to sum integers from file, where filename is a command-line argument // // version that "catches" exceptions // import scala.io.Source if (args.length < 1) { println("need command-line argument (name of file)") sys.exit(1) } try { val source = Source.fromFile(args(0)) var sum = 0 for (line <- source.getLines) { sum += line.toInt } source.close println("sum is " + sum) } catch { case e:java.io.FileNotFoundException => { println("could not open file: " + e.getMessage) } case e:java.lang.NumberFormatException => { println("invalid input: " + e.getMessage) } }