title: Preventing a MEX file from crashing in MATLAB
body: <p>I have a MEX file which I "borrowed" from someone else to help me code a semi-automated nuclear detection algorithm. The problem is that the MEX file sporadically causes a segmentation fault.  However, if the code is run with the same parameters a second time, it's fine. </p>
  
  <p>I was hoping there was a sort of <code>try/catch</code> idiom for MEX files, but after spending most of my Saturday looking for something, I couldn't find anything. </p>
  
  <p>Any help on this issue would be amazing! Otherwise, I am going to have to port the <code>.cpp</code> into MATLAB (and it's around 10,000 lines using hundreds of dependencies :-().</p>