AutoCAD: Secrets Every User Should Know

Error Handling

I used error handling in the last program example, because if you cancel the program before it ends you re left with an unexpected UCS. Now let s see how error handling works.

The purpose of error handling is to return the system to its original state if a user presses the Esc key in an attempt to stop a program prematurely. You can see why that would be a problem with programs designed to make changes in order to run a change in the current coordinate system, for example, or in the value assigned to OSMODE to control running osnaps. You don t want AutoCAD users to be unpleasantly surprised as a result of using your AutoLISP function.

Error-trapping functions are defined the same way as any other AutoLISP function using DEFUN without the C: in front of the function name. Once you define the error-trapping function, you can use it in any of your other programs by using SETQ to assign it to the AutoLISP variable *error*. The name of that variable does indeed include two asterisks. It s a special variable in AutoLISP, but it has no value until one is assigned using the SETQ function.

There are two kinds of error-trapping strategies: specific and general. The general strategy uses the UNDO command in AutoCAD to set a mark. The error handler rolls AutoCAD back to that mark in response to a program error. This strategy contains potential problems that could have dire consequences, so I won t cover it...

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: Material Handling Automation
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.