diff --git a/vm/src/frame.rs b/vm/src/frame.rs index 00d843d2a..69b1d510a 100644 --- a/vm/src/frame.rs +++ b/vm/src/frame.rs @@ -739,8 +739,8 @@ impl Frame { }; let context = match argc { 0 => vm.get_none(), // We have already got the exception, - _ => match vm.pop_exception() { - Some(exc) => exc, + _ => match vm.last_exception() { + Some(exc) => exc.clone(), None => vm.get_none(), }, }; diff --git a/vm/src/vm.rs b/vm/src/vm.rs index a677d7341..9308c0caa 100644 --- a/vm/src/vm.rs +++ b/vm/src/vm.rs @@ -931,6 +931,17 @@ impl VirtualMachine { pub fn pop_exception(&self) -> Option { self.exceptions.borrow_mut().pop() } + + pub fn last_exception(&self) -> Option> { + let exceptions = self.exceptions.borrow(); + if exceptions.is_empty() { + None + } else { + Some(Ref::map(self.exceptions.borrow(), |exceptions| { + exceptions.last().unwrap() + })) + } + } } impl Default for VirtualMachine {