Specifying a callback in Matlab after any runtime error

后端 未结 3 790
悲哀的现实
悲哀的现实 2020-12-10 18:55

Is there a way to specify code to be run whenever an error occurs in Matlab? Googling I came across RunTimeErrorFcn and daqcallback, but I believe these are specific to the

3条回答
  •  失恋的感觉
    2020-12-10 19:47

    If you wrap your code in TRY/CATCH blocks, you can execute code if an error occurs, which can be customized depending on the specific error using the MEXCEPTION object.

    try
       % do something here
    catch me
       % execute code depending on the identifier of the error
       switch me.identifier
       case 'something'
          % run code specifically for the error with identifier 'something'
       otherwise
          % display the unhandled errors; you could also report the stack in me.stack
          disp(me.message)
       end % switch
    end % try/catch
    

提交回复
热议问题