2010-09-22 13 views
10

Gibt es eine Möglichkeit, den Scala-Interpreter (der über SBT gestartet wurde) zu erzwingen, den kompletten Stack-Trace zu drucken. Standardmäßig weniger als 10 Zeilen werden angezeigt:
Wie erzwinge Interpreter Show komplette Stack-Trace?

scala> new CacheMonitoringClient 
javax.management.InstanceNotFoundException: com.bea:Name=DomainRuntimeService,Type=weblogic.management.beanservers.domainrun 
time.DomainRuntimeServiceMBean 
     at weblogic.rjvm.ResponseImpl.unmarshalReturn(ResponseImpl.java:195) 
     at weblogic.rmi.internal.BasicRemoteRef.invoke(BasicRemoteRef.java:224) 
     at javax.management.remote.rmi.RMIConnectionImpl_921_WLStub.getAttribute(Unknown Source) 
     at weblogic.management.remote.common.RMIConnectionWrapper$11.run(ClientProviderBase.java:498) 
     at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363) 
     at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:147) 
     at weblogic.security.Security.runAs(Security.java:61) 
     at weblogic.management.remote.common.RMIConnectionWrapper.getAttribute(ClientProviderBas... 

Als Abhilfe, die ich try { new CacheMonitoringClient } catch { case ex => ex.printStackTrace} bin mit (ausdrücklich die Anrufe Einwickeln, die die Ausnahmen interessiert mich werfen), aber das wirklich hässlich ...

Antwort

17

Verwenden lastException wenn Sie nur eines wollen:

scala> 1/0 
java.lang.ArithmeticException:/by zero 
    at .<init>(<console>:12) 
    at .<clinit>(<console>) 
    at RequestResult$.<init>(<console>:9) 
    at RequestResult$.<clinit>(<console>) 
    at RequestResult$scala_repl_result(<console>) 
    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.Interpreter$Request$$anonfun$loadAndRun$1$$anonfun$apply$18.apply(Interpreter.scala:981) 
    at scala.tools.nsc.Interpreter$Request$$anonfun$loadAndRun$1$$anonfun$apply$18.apply(Interpreter.scala:981) 
    at scala.util.control.Exception$Catch.apply(Exception.scala:79) 
    at scal... 
scala> lastException.printStackTrace 
java.lang.ArithmeticException:/by zero 
    at line101$object$$iw$$iw$$iw$$iw$$iw$$iw$.<init>(<console>:12) 
    at line101$object$$iw$$iw$$iw$$iw$$iw$$iw$.<clinit>(<console>) 
    at RequestResult$line101$object$.<init>(<console>:9) 
    at RequestResult$line101$object$.<clinit>(<console>) 
    at RequestResult$line101$object.scala_repl_result(<console>) 
    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.Interpreter$Request$$anonfun$loadAndRun$1$$anonfun$apply$18.apply(Interpreter.scala:981) 
    at scala.tools.nsc.Interpreter$Request$$anonfun$loadAndRun$1$$anonfun$apply$18.apply(Interpreter.scala:981) 
    at scala.util.control.Exception$Catch.apply(Exception.scala:79) 
    at scala.tools.nsc.Interpreter$Request$$anonfun$loadAndRun$1.apply(Interpreter.scala:980) 
    at scala.tools.nsc.Interpreter$Request$$anonfun$loadAndRun$1.apply(Interpreter.scala:980) 
    at scala.util.control.Exception$Catch.apply(Exception.scala:79) 
    at scala.tools.nsc.Interpreter$Request.loadAndRun(Interpreter.scala:979) 
    at scala.tools.nsc.Interpreter.loadAndRunReq$1(Interpreter.scala:578) 
    at scala.tools.nsc.Interpreter.interpret(Interpreter.scala:597) 
    at scala.tools.nsc.Interpreter.interpret(Interpreter.scala:575) 
    at scala.tools.nsc.InterpreterLoop.reallyInterpret$1(InterpreterLoop.scala:471) 
    at scala.tools.nsc.InterpreterLoop.interpretStartingWith(InterpreterLoop.scala:514) 
    at scala.tools.nsc.InterpreterLoop.command(InterpreterLoop.scala:361) 
    at scala.tools.nsc.InterpreterLoop.processLine$1(InterpreterLoop.scala:242) 
    at scala.tools.nsc.InterpreterLoop.repl(InterpreterLoop.scala:248) 
    at scala.tools.nsc.InterpreterLoop.main(InterpreterLoop.scala:558) 
    at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:72) 
    at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala) 

Oder settings.maxPrintString-0 gesetzt, obwohl das wird sich ändern, wie normale Ergebnisse zu gedruckt werden.

scala> settings.maxPrintString = 0 

scala> 1 /0 
java.lang.ArithmeticException:/by zero 
    at .<init>(<console>:12) 
    at .<clinit>(<console>) 
    at RequestResult$.<init>(<console>:9) 
    at RequestResult$.<clinit>(<console>) 
    at RequestResult$scala_repl_result(<console>) 
    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.Interpreter$Request$$anonfun$loadAndRun$1$$anonfun$apply$18.apply(Interpreter.scala:981) 
    at scala.tools.nsc.Interpreter$Request$$anonfun$loadAndRun$1$$anonfun$apply$18.apply(Interpreter.scala:981) 
    at scala.util.control.Exception$Catch.apply(Exception.scala:79) 
    at scala.tools.nsc.Interpreter$Request$$anonfun$loadAndRun$1.apply(Interpreter.scala:980) 
    at scala.tools.nsc.Interpreter$Request$$anonfun$loadAndRun$1.apply(Interpreter.scala:980) 
    at scala.util.control.Exception$Catch.apply(Exception.scala:79) 
    at scala.tools.nsc.Interpreter$Request.loadAndRun(Interpreter.scala:979) 
    at scala.tools.nsc.Interpreter.loadAndRunReq$1(Interpreter.scala:578) 
    at scala.tools.nsc.Interpreter.interpret(Interpreter.scala:597) 
    at scala.tools.nsc.Interpreter.interpret(Interpreter.scala:575) 
    at scala.tools.nsc.InterpreterLoop.reallyInterpret$1(InterpreterLoop.scala:471) 
    at scala.tools.nsc.InterpreterLoop.interpretStartingWith(InterpreterLoop.scala:514) 
    at scala.tools.nsc.InterpreterLoop.command(InterpreterLoop.scala:361) 
    at scala.tools.nsc.InterpreterLoop.processLine$1(InterpreterLoop.scala:242) 
    at scala.tools.nsc.InterpreterLoop.repl(InterpreterLoop.scala:248) 
    at scala.tools.nsc.InterpreterLoop.main(InterpreterLoop.scala:558) 
    at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:72) 
    at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala) 
+1

+1, Sind diese REPL Tipps und Tricks irgendwo dokumentiert? – missingfaktor

+0

@Missing Achten Sie darauf, auf Mailing-Listen und IRC paulp, und er wird manchmal zeigen, einige neue Trick, den er implementiert. Ansonsten drücken Sie einfach auf '' und sehen Sie, was da ist, sehen Sie, welche Methoden implementiert sind, gehen Sie in den Power-Modus und wiederholen Sie usw. –

0

Haben Sie

versucht
trace on 

in SBT vor der Konsole eingeben? Ein ist die Standardeinstellung, aber vielleicht wird sie in Ihrem Fall überschrieben.

+0

Versucht gegen SBT 0.7.4. Kein Unterschied mit Trace on/off - in beiden Fällen wird Stack-Trace angezeigt und geschnitten. –

+0

Ja, habe es einfach selbst probiert (musste zuerst installieren). Auch versucht die Spur Option, aber es gibt keinen Unterschied. Entschuldigung für den roten Hering. – Synesso

+0

Ich bemerke, dass die REPL auch Ausnahmen außerhalb eines SBT-Kontexts abschneidet, so dass es möglicherweise nicht SBT ist. – Synesso