Is there a way to catch errors with out using try catch statements?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Volkan Kandemir
le 12 Jan 2014
Réponse apportée : Image Analyst
le 12 Jan 2014
Hi,
I have created a GUI and deployed it. It works well but sometimes it gives error but user can't see it. Is there a way to show any kind of error to the user by using message box?
In other words I want to catch all errors with out using try catch statements because I have lots of functions in my program and writing try catch for all of them is time consuming.
0 commentaires
Réponse acceptée
Jan
le 12 Jan 2014
No, writing TRY-CATCH blocks is not time-consuming. It is required to catch errors and of course you cannot catch all problems automagically.
A reliable program requires an error handling and at least including the main function should be the absolut minimum.
0 commentaires
Plus de réponses (1)
Image Analyst
le 12 Jan 2014
No, you need a try catch. You don't have to have it in each and every single function. If there is an error in a function without one, then it will bubble up to the first calling routine it sees that does have one. So put this in ever function where you want to alert the user to an error:
try
% Your code goes here.
catch ME
% You get here if there was an error in this function
% or some function this function called that was unhandled.
errorMessage = sprintf('Error in function %s() at line %d.\n\nError Message:\n%s', ...
ME.stack(1).name, ME.stack(1).line, ME.message);
fprint('%s\n', errorMessage);
uiwait(warndlg(errorMessage));
end
0 commentaires
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!