pry-rescue super-fast, painless, debugging for the (ruby) masses. (See Pry to the rescue!)
gem install pry-rescue pry-stack_explorer. Then run your program with
rescue <script.rb> [arguments..]
If you want more fine-grained control over which parts of your code are rescued, you can also use the block form:
require 'pry-rescue' def test raise "foo" rescue => e raise "bar" end Pry.rescue do test end
This will land you in a pry-session:
From: examples/example.rb @ line 4 Object#test: 4: def test 5: raise "foo" 6: rescue => e => 7: raise "bar" 8: end RuntimeError: bar from examples/example.rb:7:in `rescue in test'  pry(main)>
If you need to find the reason that the exception happened, you can use the
 pry(main)> cd-cause From: examples/example.rb @ line 4 Object#test: 4: def test => 5: raise "foo" 6: rescue => e 7: raise "bar" 8: end RuntimeError: foo from examples/example.rb:5:in `test'  pry(main)>
To get back from
cd-cause you can either type
Once you've used Pry's
edit-method commands to fix your code, you can issue a
try-again command to re-run your code. (Either from the start in the case of using the
rescue script, or from the block if you're using that API).
 pry(main)> edit-method  pry(main)> whereami From: examples/example.rb @ line 4 Object#test: 4: def test => 5: puts "foo" 6: rescue => e 7: raise "bar" 8: end  pry(main)> try-again foo
If you're running rubinius, or ruby-1.9, then you can use
pry-stack_explorer. This gives you the ability to move
down the stack so that
you can get a better idea of why your function ended up in a bad state. Run
example2.rb to get a feel for what this is like.
Occasionally, when using ruby-1.8 the value for
self will be incorrect. You will still
be able to access local variables, but calling methods will not work as you expect.
On rbx we are unable to intercept some exceptions thrown from inside the C++ VM, for
example the ZeroDivisionError in
1 / 0.
Released under the MIT license, see LICENSE.MIT for details. Contributions and bug-reports are welcome.