Show in Contents
Add to Favorites
Home: Autodesk Maya Online Help
Error checking
Maya API introduction
Error logging
MStatus class
The MStatus class can determine
if a method has failed.
Many
API methods either return an instance of the MStatus class, or fill
in an instance passed as an optional parameter. The MStatus class
contains the methods error, and an overloaded operator bool,
both of which return false if the instance is holding an error status.
This means you can check the success of a call quickly, for example:
MStatus status = MGlobal::clearSelectionList();
if (!status) {
// Do error handling
...
}
If the MStatus instance
contains an error, you can do one of several things:
- Use the statusCode
method to retrieve an element of the MStatusCode enum that indicates
the reason for the failure.
- Use
the errorString method to retrieve an MString containing a detailed description
of the error.
- Use the
perror method to print the detailed description of the error to standard
error, optionally pre-pended by a string you provide.
- Use the overloaded equality and inequality
operators to compare the instance to a specific MStatusCode.
- Reset the instance to the successful
state with the clear method.