Error Handling

There are several different error handling situations encountered in OpenDCL programming: standard AutoLISP error handling, user input error handling, and OpenDCL Runtime error handling. Handling standard AutoLISP errors is not covered here.

User Input Error Handling

A properly designed graphical user interface design should, to the extent possible, prevent user input errors from occurring in the first place. OpenDCL allows controls to be dynamically disabled (or hidden) at runtime, which makes it possible to reconfigure inter-dependent controls as conditions change to ensure that only valid user input is possible. The user interface should be the first line of defense against invalid input.

Handling user input errors in OpenDCL forms must be done via event handlers for individual controls or for the form as a whole. Some controls, such as the text box control, support input filters to prevent erroneous input from being entered into the text box. Using controls like dropdown combo boxes or option buttons can limit the user's input to predetermined values. For forms that support it, the CancelClose event can be used to check input on the form and prevent the dialog from closing if invalid input is found.

Following is a typical usage scenario for the CancelClose event:

(defun HighlightFormErrors () ; Return T if there was an error, NIL otherwise
  (if (CheckForFormInputErrors) ; Call function that does the checking
    (progn
      ;; Here you can highlight the error, display a message box with more information,
      ;; or do something to fix the error (then return NIL if the error is fixed!)
      (dcl-MessageBox "Form contains invalid input!" "Error" 2 4)
      T ; Signal error found and not resolved by returning T
    )
  )
  ; Note that this function returns NIL if no errors were found
)

(defun c:Project1/Form1#OnCancelClose( Canceling /)
  ;; Return T to prevent form closing if not canceling, and unresolved errors found
  (and (/= 1 Canceling) (HighlightFormErrors)) ; Always allow form to close when canceling
)

OpenDCL Runtime Errors

Calling OpenDCL Runtime functions can result in two types of error conditions: exceptions and function failures.

Exceptions indicate a bug in your code, such as passing an incorrect argument type, or an argument with an illegal value. Unless OpenDCL messages are suppressed (see SuppressMessages), exceptions result in a message box that describes the location and nature of the exception, followed by an AutoLISP error that causes the program to stop running. Argument processing exceptions display the function name and zero-based argument index where the exception occurred.

Function failures are normally indicated by the function returning NIL. For example, attempting to set the current selection of a list box to a nonexistent list item results in a return value of NIL. These types of errors can be handled in code if desired, or in some cases simply ignored.