summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/irb.rb5
-rw-r--r--lib/irb/context.rb6
2 files changed, 9 insertions, 2 deletions
diff --git a/lib/irb.rb b/lib/irb.rb
index 16c03e964f..98bcac016d 100644
--- a/lib/irb.rb
+++ b/lib/irb.rb
@@ -439,6 +439,8 @@ module IRB
# Evaluates input for this session.
def eval_input
+ last_error = nil
+
@scanner.set_prompt do
|ltype, indent, continue, line_no|
if ltype
@@ -488,7 +490,7 @@ module IRB
signal_status(:IN_EVAL) do
begin
line.untaint
- @context.evaluate(line, line_no)
+ @context.evaluate(line, line_no, exception: last_error)
output_value if @context.echo?
exc = nil
rescue Interrupt => exc
@@ -497,6 +499,7 @@ module IRB
rescue Exception => exc
end
if exc
+ last_error = exc
handle_exception(exc)
end
end
diff --git a/lib/irb/context.rb b/lib/irb/context.rb
index 1a06ebfad1..b82aaea6a6 100644
--- a/lib/irb/context.rb
+++ b/lib/irb/context.rb
@@ -376,8 +376,12 @@ module IRB
@debug_level > 0
end
- def evaluate(line, line_no) # :nodoc:
+ def evaluate(line, line_no, exception: nil) # :nodoc:
@line_no = line_no
+ if exception
+ line = "begin ::Kernel.raise _; rescue _.class; #{line}; end"
+ @workspace.local_variable_set(:_, exception)
+ end
set_last_value(@workspace.evaluate(self, line, irb_path, line_no))
end