diff --git a/matlab_kernel/kernel.py b/matlab_kernel/kernel.py index 0e5fe8e..f402e90 100644 --- a/matlab_kernel/kernel.py +++ b/matlab_kernel/kernel.py @@ -17,7 +17,7 @@ from backports.tempfile import TemporaryDirectory from IPython.display import Image -from metakernel import MetaKernel +from metakernel import MetaKernel, ExceptionWrapper from . import __version__ @@ -89,9 +89,9 @@ def do_execute_direct(self, code): self.handle_plot_settings() if Wurlitzer: - self._execute_async(code) + retval = self._execute_async(code) else: - self._execute_sync(code) + retval = self._execute_sync(code) settings = self._validated_plot_settings if settings["backend"] == "inline": @@ -117,6 +117,8 @@ def do_execute_direct(self, code): except Exception as exc: self.Error(exc) + return retval + def get_kernel_help_on(self, info, level=0, none_on_fail=False): name = info.get("help_obj", "") out = StringIO() @@ -247,8 +249,9 @@ def _execute_async(self, code): _PseudoStream(partial(self.Error, end=""))): future = self._matlab.eval(code, nargout=0, async=True) future.result() - except (SyntaxError, MatlabExecutionError, KeyboardInterrupt): - pass + except (SyntaxError, MatlabExecutionError, KeyboardInterrupt) as exc: + stdout = exc.args[0] + return ExceptionWrapper("Error", -1, stdout) def _execute_sync(self, code): out = StringIO() @@ -260,7 +263,7 @@ def _execute_sync(self, code): except (SyntaxError, MatlabExecutionError) as exc: stdout = exc.args[0] self.Error(stdout) - return + return ExceptionWrapper("Error", -1, stdout) stdout = out.getvalue() self.Print(stdout)