Class: Pry

Inherits:
Object
  • Object
show all
Defined in:
lib/pry-rescue/core_ext.rb

Class Method Summary collapse

Class Method Details

.rescue(&block) ⇒ Object

Start a pry session on any unhandled exceptions within this block.

Examples:

Pry::rescue do
  raise "foo"
end

Returns:

  • (Object)

    The return value of the block



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/pry-rescue/core_ext.rb', line 11

def self.rescue(&block)
  raised = []

  Interception.listen(block) do |exception, binding|
    if defined?(PryStackExplorer)
      raised << [exception, binding.callers]
    else
      raised << [exception, Array(binding)]
    end
  end

rescue Exception => e
  case PryRescue.enter_exception_context(raised)
  when :try_again
    retry
  else
    raise
  end
end