Improve mex all error handling.