From 6bf1e7a2684c19f21ebc6367a39bc3e19b32e321 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sat, 13 Nov 2010 03:18:12 +0000 Subject: Another exciting development in the world of -Y... Another exciting development in the world of -Y options which I and three other people will use. Today's is -Yrich-exceptions. Use it like so: SOURCEPATH=/path/to/src scalac -Yrich-exceptions a.scala In the repl, -Yrich-exceptions will cause lastException to be bound to an Exceptional instead of old rusty Throwable. That spins up new powers: scala> Nil.head [Nil.head] (List.scala:389) (access lastException for the full trace) scala> lastException.show /* The repl internal portion of the stack trace is elided. */ [Nil.head] 386: override def isEmpty = true 387: override def head: Nothing = 388: throw new NoSuchElementException("head of empty list") *389: override def tail: List[Nothing] = 390: throw new UnsupportedOperationException("tail of empty list") 391: // Removal of equals method here might lead to an infinite recursion similar to IntMap.equals. 392: override def equals(that: Any) = that match { [line0.] (:6) [line0.] (:-1) Also try "lastException.showTable" but this is getting a little long for more excerpt. No review. --- src/compiler/scala/tools/nsc/Global.scala | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/compiler/scala/tools/nsc/Global.scala') diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala index 0f05a7fcce..d05eb26443 100644 --- a/src/compiler/scala/tools/nsc/Global.scala +++ b/src/compiler/scala/tools/nsc/Global.scala @@ -12,7 +12,7 @@ import compat.Platform.currentTime import scala.collection.{ mutable, immutable } import io.{ SourceReader, AbstractFile, Path } import reporters.{ Reporter, ConsoleReporter } -import util.{ ClassPath, SourceFile, Statistics, BatchSourceFile, ScriptSourceFile, ShowPickled, returning } +import util.{ Exceptional, ClassPath, SourceFile, Statistics, BatchSourceFile, ScriptSourceFile, ShowPickled, returning } import reflect.generic.{ PickleBuffer, PickleFormat } import symtab.{ Flags, SymbolTable, SymbolLoaders } @@ -147,6 +147,11 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable def logError(msg: String, t: Throwable): Unit = () def log(msg: => AnyRef): Unit = if (opt.logPhase) inform("[log " + phase + "] " + msg) + def logThrowable(t: Throwable): Unit = error(throwableAsString(t)) + def throwableAsString(t: Throwable): String = + if (opt.richExes) Exceptional(t).force().context() + else util.stringFromWriter(t printStackTrace _) + // ------------ File interface ----------------------------------------- private val reader: SourceReader = { @@ -227,6 +232,7 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable def logClasspath = settings.Ylogcp.value def printLate = settings.printLate.value def printStats = settings.Ystatistics.value + def richExes = settings.YrichExes.value def showTrees = settings.Xshowtrees.value def target = settings.target.value def typerDebug = settings.Ytyperdebug.value -- cgit v1.2.3