New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capture exceptions and expose them to the REPL #289

Closed
lihaoyi opened this Issue Dec 7, 2015 · 3 comments

Comments

Projects
None yet
1 participant
@lihaoyi
Owner

lihaoyi commented Dec 7, 2015

EDIT: Original issue was for ThreadDeath, but this will be useful for any exception

This can be exposed to the REPL as a value, and would be useful for a variety of reasons:

  • You may want to know "how far" execution went before you interrupted it. Inspecting the stack trace would give you some indication of "where" in the executed code it had reached.
  • A prime case of interrupting code is when it infinite-loops; in such a case you'd like to know where the infinite loop is! Since that's where the program is spending "all" its time, the stack trace (perhaps repeated once or twice) should give a very good indication of where the program is getting stuck
  • If the program is blocked/deadlocked on something indefinitely when you interrupt it (e.g. out of frustration) the stack trace will point directly to the offending line of code.

Currently it just prints

haoyi-static-analysis@ while(true)()
^C
Interrupted!

When you interrupt it. We could instead assign it to some value

haoyi-static-analysis@ while(true)()
^C
val res12: InterruptedException = ...

Which would both show the user that it was interrupted, and let them dig deeper if they wished to

@lihaoyi lihaoyi added the enhancement label Dec 7, 2015

@lihaoyi

This comment has been minimized.

Owner

lihaoyi commented Dec 12, 2015

Actually this might not be unique to ThreadDeath; any exception that gets thrown should be made available as a val, as sometimes they contain useful metadata e.g. FastParse's ParseErrors or Ammonite-Ops's ShelloutExceptions.

By making these uncaught exceptions available to the shell session by default, we could save a lot of annoying re-running-code-with-try-catch during interactive development and exploration

@lihaoyi lihaoyi changed the title from Capture stack trace of ThreadDeath exception when execution is interrupted to Capture exceptions and expose them to the REPL Dec 13, 2015

@lihaoyi

This comment has been minimized.

Owner

lihaoyi commented Dec 13, 2015

Turn out the normal REPL has a mutable lastException: Throwable definition. This is halfway there, but isn't ideal: you still need to cast the Throwable into the correct type before being able to manipulate it usefully. The REPL should already know what the type is, and by exposing it as a val of the correct type, you won't need to do the casting yourself.

@lihaoyi

This comment has been minimized.

Owner

lihaoyi commented Feb 23, 2016

This has been fixed in 0.5.5; thanks @coderabhishek !

@lihaoyi lihaoyi closed this Feb 23, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment