Throw Error in TimerFcn
Mostra commenti meno recenti
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'
Risposta accettata
Più risposte (1)
Ameer Hamza
il 8 Apr 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 Commenti
Sohil Shrestha
il 8 Apr 2020
Ameer Hamza
il 8 Apr 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
il 8 Apr 2020
Categorie
Scopri di più su Programming in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!