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: