Is there a way to catch errors with out using try catch statements?
Mostrar comentarios más antiguos
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.
Respuesta aceptada
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
Categorías
Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!