Multiple cause exception handling

2 ビュー (過去 30 日間)
Umit Sharip
Umit Sharip 2018 年 2 月 28 日
コメント済み: Umit Sharip 2018 年 3 月 1 日
Consider this script,
try
% code
catch e
fprintf(1,'Exception identifier: %s\n',e.identifier);
fprintf(1,'Exception message: %s\n',e.message);
end
When using try & catch to handle exceptions, if exception has multiple causes, it throws something like this:
Exception occurred!
Exception identifier: MATLAB:MException:MultipleErrors
Exception message: Error due to multiple causes.
Any way to parse the exceptions out one-by-one?

採用された回答

Jan
Jan 2018 年 2 月 28 日
編集済み: Jan 2018 年 2 月 28 日
Does this help:
R = getReport(e);
? Otherwise check the list in e.cause and display it in a loop.
...
catch ME
if length(ME.cause) > 1
for k = 1:length(ME.cause)
fprintf('Exception message: %s\n', ME.cause{k}.message);
end
else
fprintf('Exception message: %s\n', ME.message);
end
end
UNTESTED CODE I cannot run it currently. Maybe you have to adjust it, but I hope the idea got clear.
  1 件のコメント
Umit Sharip
Umit Sharip 2018 年 3 月 1 日
Thanks, getReport(e) works.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by