Improved error handling on entry to mex files