How not to repeat the whole code after the try catch loop ?
Show older comments
Hi all
is there a line to indicate the main code between the try catch loop to avoide rewriting it ?
5 Comments
What is a try catch loop? try catch means branching in case of errors, but there is no loop. What is "the main code" and what might "between the loop" mean? For "between" there need to be at least 2 limits, but "between the loop" is only one.
"Between the bag there sat a man."
Please post some code, which demonstrates, what you are asking for. Prefer to edit the question instead of adding this information in a comment.
farzad
on 27 Jun 2019
Jan
on 27 Jun 2019
What does "how the structure is suggested" mean? If you are interested in assistance to solve your problem, it is useful to answer the questions for clarifications.
farzad
on 28 Jun 2019
Jan
on 28 Jun 2019
@farzad: You can be more clear: Simply explain, which problem you want to solve.
In this code:
for j = 1:10
try
... your code...
catch
warning('found error in %dth file', j);
continue
end
end
you do not have to write any code twice. The first comment (green line) is a placeholder for your code, and the second comment is some other code, which is executed only, if the first one ran without an error. An alternative version of the above code:
for j = 1:10
try
... your code...
... your code, if the above statement succeed
catch
warning('found error in %dth file', j);
end
end
So do you see now, that you do not write anything twice here?
You still did not mention, which problem you want to solve and you assume that anything must be written twice. My questions for clarifications are not answered yet.
You are not a newcomer in this forum, but please let me ask you to read this again: How to ask a good question
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements 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!