User`s guide
Programming
15-19
Internal Packages Make Reserved Functions Easy to Identify
The MathWorks
®
reserves the use of packages named internal for utility functions
used by internal MATLAB code. Functions that belong to an internal package are
intended for The MathWorks use only. Using functions that belong to an internal
package is strongly discouraged. These functions are not guaranteed to work in a
consistent manner from one release to the next. In fact, any of these functions and
classes may be removed from the MATLAB software in any subsequent release without
notice and without documentation in the product release notes.
See Internal Utility Functions in the Programming Fundamentals documentation for
more information.
Use of lasterror, lasterr, rethrow(errStruct) Not Recommended
In version 7.5, The MathWorks introduced a new class called MException for use in error
handling. Prior to this change, the lasterr and, more recently, lasterror functions kept
track of only the one most recently thrown error. The state of any errors thrown before
that was overwritten by newer errors. Also, this error state was globally accessible,
which means that it could be unintentionally modified or destroyed either during an
interactive session or by another function.
When using the newer, object-based error mechanism, every error generated by a
MATLAB function stores information about what caused the error in a separate
MException object. This enables MATLAB to store information about multiple errors,
adds the capacity to store new fields of information including links to related errors, and
also resolves the problem of being globally accessible.
The MathWorks now discourages the use of the lasterr and lasterror functions
because the information they return is global and thus has the potential to be
corrupted. You should replace the use of these two functions with the new style of
try-catch statement that captures an MException object to represent the error. When
entering commands at the MATLAB command line, you can also use the static method
Mexception.last to retrieve information on the most recent error. For more information
on this method of error handling, see The MException Class.
This change also affects which form of the rethrow function to use when reissuing
an exception. The original rethrow function, in use since before version 7.5, accepts
only a structure as input. Because this structure is typically obtained using the
lasterror function, this form of rethrow should be avoided. The later form of