// // program to sum integers from file, where filename is a command-line argument // // version that "catches" exceptions // if (args.length < 1) { println("need command-line argument (name of file)") } else { try { val source = scala.io.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) } } }