Is there a way to catch errors with out using try catch statements?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Volkan Kandemir
el 12 de En. de 2014
Respondida: Image Analyst
el 12 de En. de 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 comentarios
Respuesta aceptada
Jan
el 12 de En. de 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 comentarios
Más respuestas (1)
Image Analyst
el 12 de En. de 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 comentarios
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!