How to restart my program from a try/catch statment
5 次查看(过去 30 天)
显示 更早的评论
I am trying set up a try/catch statment for error detection within my program.
If an error occurs in the try statment, i would like to change a variable (by -1) and then retry the entire program, How to i go about this?
0 个评论
采纳的回答
Chris
2021-10-28
编辑:Chris
2021-10-28
With recursion, you could do something like this:
val = 1;
startThisAgain(val)
function startThisAgain(val)
disp('Beginning Program')
try
disp('Trying')
assert(~mod(val,2) == 1,'This is an error')
disp('Done!')
catch
disp('Caught')
val = val+1;
startThisAgain(val)
end
end
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!