Schuerta
Schuerta

Reputation: 41

Matlab alternative to try/catch or continue after catch?

im trying to set 70+ tiff tags to an image file that may or may not exist, If i try to set a tag and it throws an exception because the tag doesnt exist in this img file, i want to continue to try to set the remaining tags and i dont want to have 70 try/catch statements in sequence.

Any way to have it continue execution immidiately where it left off?

Ex: not

try
     %matlab code to set tag1
catch ME
     %do nothing
end
try
     %matlab code to set tag2
catch ME
     %do nothing
end
try
     %matlab code to set tag3
catch ME
     %do nothing
end

but instead this:

try
     %Matlab code to set tag1, continue regardless of exception
     %Matlab code to set tag2 continue regardless of exception
     %Matlab code to set tag3, continue regardless of exception
catch ME
    %do nothing skip this tag and execute next line up there ^^^
end

Upvotes: 1

Views: 685

Answers (1)

dpdp
dpdp

Reputation: 322

you can use try catch in a while loop:

count = 0;
err_count = 0;

while count == err_count

    try
        % my attmept to understand the tags you asked about
        if  your_tag_number(count) ~= the_tag_you_want;
            error
        end

    catch ME
        err_count = err_count + 1;
    end

    count = count + 1;
end

Upvotes: 2

Related Questions