Elgrint supports three mechanisms for reporting errors: exceptions, error flags, and assertion macros.
- Exceptions are the primary error reporting mechanism. They are used by all window classes, MApp, MSys, MImage, MFile, and MTextFile. The exceptions mechanism can also report warnings and notifications. Exceptions are generated via MApp::genException and related functions, and handled by MHandleException
- Error flags are used by all collection classes, except for MImage, to indicate a memory error or a numeric overflow (which is kind of the same thing). This is the only type of error possible in a collection class (except for MImage). The exceptions mechanism cannot be used there because of performance and compiler issues. The error flag is set using Collection::setError (usually internally), and revealed using Collection::isError. Alternatively, each mutator function returns !isError() - the logical negative of the error flag (i.e. false on failure, true on success). Sometimes using this return value as an error indicator is easier than calling isError directly
- Assertion macros are used for debugging purposes almost everywhere. They only exist in DEBUG mode for performance reasons. There are two very similar assertion macros: M_ASSERT(Cond) and M_PARAM_CHECK(Cond,Text). M_ASSERT is used for internal consistency checks, and M_PARAM_CHECK is used for detecting improper input parameter values
- Use GenException whenever possible and practical
- Use M_ASSERT for internal self-consistency checks as much as possible
- Use M_PARAM_CHECK for testing user input if the exception mechanism should not be used (for example when designing your own collections)
- Use error flags while working with collections or designing your own collections
Let us know
Please Contact us to report any errors on this page, or to suggest any improvements.