diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index e19c5d9..fbb9461 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -208,6 +208,13 @@ class ExecutionResult(object): def success(self): return (self.error_before_exec is None) and (self.error_in_exec is None) + def raise_error(self): + """Reraises error if `success` is `False`, otherwise does nothing""" + if self.error_before_exec is not None: + raise self.error_before_exec + if self.error_in_exec is not None: + raise self.error_in_exec + class InteractiveShell(SingletonConfigurable): """An enhanced, interactive shell for Python.""" @@ -2714,11 +2721,8 @@ class InteractiveShell(SingletonConfigurable): try: for cell in get_cells(): result = self.run_cell(cell, silent=True, shell_futures=shell_futures) - if not result.success and raise_exceptions: - if result.error_before_exec is not None: - raise result.error_before_exec - else: - raise result.error_in_exec + if raise_exceptions: + result.raise_error() elif not result.success: break except: