The AutoCAD environment is complex and interactive, so ObjectARX applications must be robust. ObjectARX provides several error-handling facilities. The result codes returned during “handshaking” with AutoLISP indicate error conditions, as do the result codes library functions returned to the application. Functions that prompt for input from the AutoCAD user employ the built-in input-checking capabilities of AutoCAD. In addition, three functions let an application notify users of an error: acdbFail(), acedAlert(), and acrx_abort().
The acdbFail() function simply displays an error message (passed as a single string) at the AutoCAD Command prompt. This function can be called to identify recoverable errors such as incorrect argument values passed by the user.
The statement in the following example calls acdbFail() from a program named test.arx:
acdbFail("invalid osnap point\n");
The acdbFail() function displays the following:
Application test.arx ERROR: invalid osnap point
You can also warn the user about error conditions by displaying an alert box. To display an alert box, call acedAlert(). Alert boxes are a more emphatic way of warning the user, because the user has to choose OK before continuing.
For fatal errors, acrx_abort() should be called. This function prompts the user to save work in progress before exiting. The standard C++ exit() function should not be called.
To obtain detailed information about the failure of an ObjectARX function, inspect the AutoCAD system variable ERRNO. When certain ObjectARX function calls (or AutoLISP function calls) cause an error, ERRNO is set to a value that the application can retrieve by a call to acedGetVar(). ObjectARX defines symbolic names for the error codes in the header file ol_errno.h, which can be included by ObjectARX applications that examine ERRNO. These codes are shown in the ObjectARX Reference.