Multiple cause exception handling

4 vues (au cours des 30 derniers jours)
Umit Sharip
Umit Sharip le 28 Fév 2018
Commenté : Umit Sharip le 1 Mar 2018
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?

Réponse acceptée

Jan
Jan le 28 Fév 2018
Modifié(e) : Jan le 28 Fév 2018
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 commentaire
Umit Sharip
Umit Sharip le 1 Mar 2018
Thanks, getReport(e) works.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by