how to save errors

19 ビュー (過去 30 日間)
nirit
nirit 2019 年 5 月 19 日
編集済み: nirit 2019 年 5 月 21 日
I have the following code:
for i=1:10
output1=some_function1(input1,input2)
output2=some_function2(output1,input1,input2,input3)
output3=some_function2(output2)
.
.
.
end
and I want to add try and catch to it, since each function takes look time to compute. and sometimes I get error which I want to deal with later on.
so how can I save the string error which I see on the screen without the try-catch, info on where the error happened?
for example, say that when i=5 it in line 111 of some_function2 I get an error.
I want to save some "failures" struct like the following:
failures(end+1).iter=5;
failures(end).str='some_function2 in line 111"';
how can I save the 'some_function2 in line 111"' str which I see on the command window?

採用された回答

Jan
Jan 2019 年 5 月 19 日
failures = struct('iter', {}, 'str', {});
for i = 1:10
try
output1=some_function1(input1,input2)
output2=some_function2(output1,input1,input2,input3)
output3=some_function2(output2)
catch ME
failure(end + 1).iter = i;
failure(end + 1).str = getReport(ME);
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by