Pause on error, run calculation in that workspace, and resume the script

8 views (last 30 days)
I have 88 "Cases" that I know will throw an error when running a function. I would like to automate saving a value from this functions workspace, kill that function excecution, and then continuing a for loop to the next case. I've tried try and catch but it seems to still skip past the desired workspace. There is a manual workaround using pause on error when running and setting a break point on the error command, but I was hoping to automate this process.
  1 Comment
VINAYAK LUHA
VINAYAK LUHA on 30 Jan 2024
Is it possible to add some sample fail cases, function code and the variable from function workspace which you want to save?

Sign in to comment.

Answers (1)

Fangjun Jiang
Fangjun Jiang on 30 Jan 2024
Edited: Fangjun Jiang on 30 Jan 2024
What do you mean by "skip past the desired workspace"? I think it should work using try-catch.
If you don't have access to the source code/inside contents of the function, then I think you are out of luck. The try-catch inside the for-loop but outside of the function can only catch when the error occured at the fucntion, by then, the function workspace is destroyed.
So, it is better to put try-catch inside the function, if it is possible.
for k=1:100
MyFun
end
function MyFun
try
% do your routine
catch
% save your workspace
return
end

Categories

Find more on Programming in Help Center and File Exchange

Tags

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!