handleError - generic error-handling function

版本 1.0.0.0 (1.9 KB) 作者: Yair Altman
A general-purpose error-handling function with an ability to register automatic cleanup actions
2.0K 次下载
更新时间 2007/5/24

无许可证

handleError is a general-purpose error-handling function. The user can register cleanup actions that will automatically be activated in case of error. If an error occurred and handleError is called, then a hyper-linked stack-trace is displayed in the command window.

Syntax:
ERRMSG = handleError
ACTIONIDX = handleError('register',ACTION)
ERRMSG = handleError('unregister',ACTIONIDX)

ACTIONIDX = handleError('register',ACTION) will register cleanup actions to be performed in case of error. ACTION may be a single string (e.g., 'msgbox(lasterr)') or a cell array with arguments for the sprintf function (e.g., {'set(%.19g,''Pointer'',''arrow'')',gcf}). The returned ACTIONIDX is the sequential cleanup action index.

ERRMSG = handleError('unregister',ACTIONIDX) will perform and unregister cleanup action(s) ACTIONIDX. The returned ERRMSG is the last error msg.

ERRMSG = handleError; will automatically perform and unregister any registered cleanup actions. Then, the last error message will be displayed in the Command Window, followed by a hyper-linked stack trace of that error. This format is the one that should be used within catch blocks (see Example):

Example:
try
. cleanups(1)=handleError('register',{'set(%.19g,''Pointer'',''arrow'')',gcf});
. cleanups(2)=handleError('register','disp(''finished processing!'')');
. set(gcf,'Pointer','watch'); drawnow;
. ... some complex computation ...
. handleError('unregister',cleanups); %eval & unregister cleanup actions
catch
. handleError; %display error stack; eval & unregister cleanup actions
end

Compatibility:
Created on Matlab 7, but should work on earlier versions too. Please report any issues to altmany (at) gmail dot com.

引用格式

Yair Altman (2024). handleError - generic error-handling function (https://www.mathworks.com/matlabcentral/fileexchange/15059-handleerror-generic-error-handling-function), MATLAB Central File Exchange. 检索时间: .

MATLAB 版本兼容性
创建方式 R14SP3
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Scope Variables and Generate Names 的更多信息

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
1.0.0.0

updated description text