Skip to content
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

Better error-handling from Engine #14

Open
bbarker opened this issue May 29, 2020 · 2 comments
Open

Better error-handling from Engine #14

bbarker opened this issue May 29, 2020 · 2 comments

Comments

@bbarker
Copy link
Collaborator

bbarker commented May 29, 2020

Possibly related: #10

Currently, some errors, like those causes by improper (or buggy) use of clearVar, cause output to happen in stderr (I think). We could detect this in MATLAB with try-catch and return MATLAB incantation of Either. See here for a discussion on the issue of using try/catch, however.

So, other avenues of attack may need to be considered as well.

@bbarker
Copy link
Collaborator Author

bbarker commented May 29, 2020

I think #15 may provide a solution; we could ship a function tryToEither.m:

function result =  tryToEither(fun, varargin)
result =  struct('left', struct('message', 'tryToEither: try nor catch succeeded'));
try
  funResult = fun(varargin{:});
  result = struct('right', statementString);
catch ex
  result = struct('left', ex);
end
end

Of course we may need a similar function shipped to create a function handle, haven't tested that yet (or seen any evidence of function handle support in the MATLAB Engine API).

@bbarker
Copy link
Collaborator Author

bbarker commented Jun 10, 2020

Also, regarding Haskell-exceptions and errors, I'm guessing that foreign calls can't initiate an exception (at least not one that can be handled), unless we implement a wrapper as described above. One possible caveat might be: if the FFI call somehow called back into Haskell, and an exception was thrown in the Haskell code at that point.

Chessai says: i believe that the thread running the c code will just inherit whatever exception is thrown. you can catch them from haskell using the handlers in posix (which is not supported on windows). Minimalist segfaulting haskell program: https://gist.github.com/chessai/a9ae3d56b8f64ea6dce6065808fa3726

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant