Reputation: 684
When a Mex-function produces a segmentation-fault, a MATLAB System Error window pops-up and choosing Attempt to Continue
leads to a lot of useless debugging information which is purred into the command window.
Is it possible to catch these mex-exceptions in Matlab or at least to be able to process them later on?
Unfortunately, following conventional try/catch won't work in this cases:
try
myMex(input)
catch
error('Mex failed')
end
Please note that I do not want to catch the error inside the mex.
Upvotes: 0
Views: 911
Reputation: 2342
If you have the source code, you can compile the mex with debug mode (-g
flag).
Then, depending on your platform, you can run the mex in debug mode (check out Troubleshoot MEX-Files on MATLAB docs).
If you are running in windows, you can use Visual Studio and select debug->Attach to Process and choose MATLAB. Then you can run your mex file, which will trigger an exception (and a breakpoint) in VS rather than MATLAB.
Upvotes: 1