How to force interpreter show complete stack trace?

前端 未结 2 541
难免孤独
难免孤独 2020-12-14 04:35

Is there any way to force Scala interpreter (started through SBT) to print complete stack trace. By default, less than 10 lines are displayed:

scala>         


        
2条回答
  •  伪装坚强ぢ
    2020-12-14 05:10

    Use lastException if you want just one thing:

    scala> 1 / 0
    java.lang.ArithmeticException: / by zero
        at .(:12)
        at .()
        at RequestResult$.(:9)
        at RequestResult$.()
        at RequestResult$scala_repl_result()
        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$.(:12)
        at line101$object$$iw$$iw$$iw$$iw$$iw$$iw$.()
        at RequestResult$line101$object$.(:9)
        at RequestResult$line101$object$.()
        at RequestResult$line101$object.scala_repl_result()
        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)
    

    Or set settings.maxPrintString to 0, though that will change how normal results are printed too.

    scala> settings.maxPrintString = 0
    
    scala> 1 /0
    java.lang.ArithmeticException: / by zero
        at .(:12)
        at .()
        at RequestResult$.(:9)
        at RequestResult$.()
        at RequestResult$scala_repl_result()
        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)
    

提交回复
热议问题