Throw Error in TimerFcn
Mostrar comentarios más antiguos
I want to throw an error when timer fires up .
try
timeout = timer('TimerFcn','error(''TIMEOUT OCCURED'');','StartDelay',0.01);
start(timeout);
'''Some Code'''
stop(timeout);
delete(timeout);
catch ME
delete(timeout);
disp('Error is caught')
''' Do something else '''
end
Upon executing, I am getting
Error while evaluating TimerFcn for timer 'timer-47'
Respuesta aceptada
Más respuestas (1)
Ameer Hamza
el 8 de Abr. de 2020
TimerFcn can either be a function handle or the name of a function. To display anything, you need to use a function. For example
timeout = timer('TimerFcn',@(~,~) disp('error(''This is error'');'),'StartDelay',0.01);
3 comentarios
Sohil Shrestha
el 8 de Abr. de 2020
Ameer Hamza
el 8 de Abr. de 2020
Ok. I get your point. But the example you referred is not related to error handling. Can you tell why do you want to do such a thing? Isn't it logical to write your TimerFcn callback such that it executes the code inside 'catch' block?
Sohil Shrestha
el 8 de Abr. de 2020
Categorías
Más información sobre Programming en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!