Throw Error in TimerFcn
Afficher commentaires plus anciens
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'
Réponse acceptée
Plus de réponses (1)
Ameer Hamza
le 8 Avr 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 commentaires
Sohil Shrestha
le 8 Avr 2020
Ameer Hamza
le 8 Avr 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
le 8 Avr 2020
Catégories
En savoir plus sur Programming dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!