Errordlg for any given Matlab error

4 次查看(过去 30 天)
Hi,
I have a question about inner Matlab error management. Right now I have quite a large program with a lot of variables and functions that cumulated over my code writting and I'm 100 percent sure that I did not catch all the bugs and mistakes in the program and I don't want it to crash completely when is used by layman user. So, is there a way to display errordlg message and for example restart the program when there will be any given error directly by Matlab (for example when I forgot to declare a global variable etc.)?
Thanks for answers, Peter

采纳的回答

Petr
Petr 2013-4-3
For those that will have the same problem...solution might look something like this if you use GUI...
function varargout = Program(varargin)
try
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @program_OpeningFcn, ...
'gui_OutputFcn', @program_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
catch exception
beep
h = errordlg('Unexpected error, the program will be restarted.','Syntax
error','modal');
uiwait(h)
Program
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by