Throw Error in TimerFcn
Show older comments
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'
Accepted Answer
More Answers (1)
Ameer Hamza
on 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 Comments
Sohil Shrestha
on 8 Apr 2020
Ameer Hamza
on 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
on 8 Apr 2020
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!