Exceptions vs. Errors in Matlab

后端 未结 2 503
刺人心
刺人心 2021-02-13 07:01

Matlab provides two mechanisms for signaling that something has gone wrong: the errorfunction and the language\'s exception-handling mechanisms MException

相关标签:
2条回答
  • 2021-02-13 07:36

    Those two cases are virtually equivalent (if you catch an error or exception the only difference is that the 'cause' property's cell is allocated slightly differently). The error function just makes it easy to generate and throw exceptions. The one nice thing about MException is that you can create an MException object and pass it around as a variable, change its properties (e.g., adding a cause), and throw or rethrow when needed. Most of the time you'll just want to use error however.

    This page from the MathWorks includes lots of details on the MException class.

    0 讨论(0)
  • 2021-02-13 07:52

    There is some more useful information on this thread on MATLAB Answers.

    The answer says that error is much older and that MException is newer and more flexible. Error has been modified to create an MException.

    Error is considered easier to use and targetted at MATLAB end users from the Scientific and Engineering community. MException is more advanced (in that ME objects can be modified and rethrown) and is targeted at the software development community.

    0 讨论(0)
提交回复
热议问题