Malcolm Sharpe
unread,Mar 27, 2012, 12:30:07 PM3/27/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to scala-user
Hi, I'm just beginning to learn Scala from the book "Programming in
Scala". My question is whether there is a way to get more concise and
helpful error messages from scripts.
For example, consider the example program helloarg.scala from the
book:
println("Hello, " + args(0) + "!")
If I (incorrectly) run this with "scala helloarg.scala", forgetting
the argument, then I get the following error message:
java.lang.ArrayIndexOutOfBoundsException: 0
at Main$$anon$1.<init>(helloarg.scala:1)
at Main$.main(helloarg.scala:1)
at Main.main(helloarg.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
at java.lang.reflect.Method.invoke(Method.java:597)
at scala.tools.nsc.util.ScalaClassLoader$$anonfun$run
$1.apply(ScalaClassLoader.scala:78)
at scala.tools.nsc.util.ScalaClassLoader
$class.asContext(ScalaClassLoader.scala:24)
at scala.tools.nsc.util.ScalaClassLoader
$URLClassLoader.asContext(ScalaClassLoader.scala:88)
at scala.tools.nsc.util.ScalaClassLoader
$class.run(ScalaClassLoader.scala:78)
at scala.tools.nsc.util.ScalaClassLoader
$URLClassLoader.run(ScalaClassLoader.scala:101)
at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:33)
at scala.tools.nsc.ObjectRunner$.runAndCatch(ObjectRunner.scala:40)
at scala.tools.nsc.ScriptRunner.scala$tools$nsc$ScriptRunner$
$runCompiled(ScriptRunner.scala:171)
at scala.tools.nsc.ScriptRunner$$anonfun$runScript
$1.apply(ScriptRunner.scala:188)
at scala.tools.nsc.ScriptRunner$$anonfun$runScript
$1.apply(ScriptRunner.scala:188)
at scala.tools.nsc.ScriptRunner$$anonfun$withCompiledScript$1.apply
$mcZ$sp(ScriptRunner.scala:157)
at scala.tools.nsc.ScriptRunner$$anonfun$withCompiledScript
$1.apply(ScriptRunner.scala:131)
at scala.tools.nsc.ScriptRunner$$anonfun$withCompiledScript
$1.apply(ScriptRunner.scala:131)
at scala.tools.nsc.util.package$.waitingForThreads(package.scala:26)
at scala.tools.nsc.ScriptRunner.withCompiledScript(ScriptRunner.scala:
130)
at scala.tools.nsc.ScriptRunner.runScript(ScriptRunner.scala:188)
at scala.tools.nsc.ScriptRunner.runScriptAndCatch(ScriptRunner.scala:
201)
at scala.tools.nsc.MainGenericRunner.runTarget
$1(MainGenericRunner.scala:58)
at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:
80)
at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:
89)
at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
Yikes! Compare with the error message produced from a comparable
Python script:
Traceback (most recent call last):
File "helloarg.py", line 3, in <module>
print 'Hello, ' + sys.argv[1] + '!'
IndexError: list index out of range
Is there something I can do about this to get better error messages?
To clarify, what I like more about the Python error message is:
- The most important information goes at the bottom. When reading
console output, this is helpful.
- The traceback starts in my program, omitting runner cruft that isn't
meaningful or useful to me.
- There's some other helpful information included: the source of the
line where the error occurred, a written description of the error, and
so on.
Thanks!