The AutoLISP language provides several functions for handling errors.
The proper handling of errors allows your program to exit gracefully and with an expected result. Using the error handling functions of the AutoLISP programming language allows you to do the following:
The following functions are useful to handle errors encountered by your programs:
If your program contains more than one error in the same expression, you cannot depend on the order in which AutoLISP detects the errors. For example, the inters function requires several arguments, each of which must be either a 2D or 3D point list. A call to inters like the following:
(inters 'a)
Two errors are encountered: too few arguments and invalid argument type. You will receive either of the following error messages:
; *** ERROR: too few arguments ; *** ERROR: bad argument type: 2D/3D point
Your program should be designed to handle either error.
(defun foo () (print "Evaluating foo") '(1 2)) (defun bar () (print "Evaluating bar") 'b) (defun baz () (print "Evaluating baz") 'c)
Observe how an expression using the inters function is evaluated in AutoCAD:
Command: (inters (foo) (bar) (baz))
"Evaluating foo"
"Evaluating bar"
"Evaluating baz"
; *** ERROR: too few arguments
Each argument was evaluated successfully before AutoLISP passed the results to inters and discovered that too few arguments were specified.
In AutoCAD R14 and earlier, the same expression evaluated as follows:
Command: (inters (foo) (bar) (baz))
"Evaluating foo"
"Evaluating bar" error: bad argument type
AutoLISP evaluated (foo), then passed the result to inters. Since the result was a valid 2D point list, AutoLISP proceeds to evaluate (bar), where it determines that the evaluated result is a string, an invalid argument type for inters.