Error API for Application Development

バージョン 1.2.0.1 (21.5 KB) 作成者: Malcolm Wood
An API to assist with error reporting in MATLAB applications
ダウンロード: 1.4K
更新 2016/9/1

ライセンスの表示

Those of us developing graphical applications in MATLAB do not want our users to be exposed to the internals of our work. Unfortunately, the built-in "error" function prefixes to the error message the name of the function which threw that error, which is unlikely to be of any interest to the user and serves only to confuse. This is particularly true when using the MATLAB Compiler to create applications for use by people with no knowledge of MATLAB.
The API supplied here provides a wrapper for the "error" function which stores the error message without that extra line, so that it can be retrieved later and shown to the user.

To use this functionality, replace calls to "error" with identical calls to "xError", e.g.:

error('MyApplication:MyErrorIdentifier','This operation did not work because %s',reason);

becomes:

xError('MyApplication:MyErrorIdentifier','This operation did not work because %s',reason);

Also, replace calls to "lasterr" or "lasterror" with "xLastErr" or "xLastError" respectively, creating e.g.

function my_uicallback
try
my_function_name;
catch
errordlg(xLastErr,'My Application','modal');
end

The error message shown to the user is then simply (e.g.):

This operation did not work because the file was not found

instead of:

Error using ==> my_function_name
This operation did not work because the file was not found

For debugging purposes, the error message and the call stack at the point when it was thrown are stored in a log file in the user's preference directory. The log can also be used to store status messages from the application. See function xLog.

If the last error was thrown using "error" instead of "xError", "xLastError" detects this. This ensures that the wrong error message is never shown, and means that errors thrown by built-in functions (or the interpreter) can be logged too.

Use the buttons in the supplied demo function "xDemo" to see the difference.

引用

Malcolm Wood (2025). Error API for Application Development (https://www.mathworks.com/matlabcentral/fileexchange/10628-error-api-for-application-development), MATLAB Central File Exchange. に取得済み.

MATLAB リリースの互換性
作成: R14SP3
すべてのリリースと互換性あり
プラットフォームの互換性
Windows macOS Linux
カテゴリ
Help Center および MATLAB AnswersError Functions についてさらに検索

Community Treasure Hunt

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

Start Hunting!
バージョン 公開済み リリース ノート
1.2.0.1

Updated license

1.2.0.0

Added copyright notices.

1.1.0.0

Review

1.0.0.0

Formatting