Skip to content

returning ExceptionWrapper object if excution halts with error #114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions matlab_kernel/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__

Expand Down Expand Up @@ -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":
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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)

Expand Down