我正在尝试在代码中实现错误报告系统,因此我在启动程序时运行的函数周围放置了一个 try/catch。它是一个编程 GUI,因此大多数子函数都是按钮或其他 GUI 元素的回调。然而,每当这些子函数中抛出错误时,它都不会被捕获。一些子功能在其他文件中定义,因为它们是其他编程 GUI 文件。
我的问题是,是否有办法捕获超过一个函数级别深度的错误?
下面的例子:
我运行 CeleST 来启动程序
function CeleST
try
% Global try-catch
CSTMainWindow()
catch exception
generateReport(exception) % bugReporter
end
CST MainWindow 是一个编程 GUI 文件,这里是其中一个按钮:
uicontrol('parent',mainPanel,'style','pushbutton','string','1. Process videos...','position',[500 yFilters+hFilters+10 170 60],'callback',@processVideo);
但是 processVideo 中的错误未被捕获
流程视频:
function processVideo(hObject,eventdata) %#ok<INUSD>
set(mainFigure,'Visible','off');
CSTProcessVideos % Programmatic GUI File for another window
set(mainFigure,'Visible','on');
flagConsistentButton = false;
checkSequences
populateFilters
end
即使将未定义的变量放入子函数中也会引发错误,但它们不会被我的 try/catch 捕获。有什么建议还是我做错了什么?我真的必须在所有东西周围放置 try-catch 块吗?