Wednesday
AutoLISP, Autocad, ProgrammingError handling in AutoLISP programmes 2
All AutoLISP versions
In my previous article, I have explained the ‘*error*’ function among the error explanatory functions seen in Table 1. The subjects of this article however are ‘alert’, ‘exit’ and ‘quit’ functions.
(alert msg) function:

Table.1
This function creates a message box on the screen (Figure 1).

Figure 1
These kinds of message boxes are used for recoverable errors or giving another change to the user. Using this kind of error message box gives the user nothing than an extra work (pressing ENTER or using mouse) since the error programme finished its work in our example. Controlling the input data given from the user, it is more appropriate to output a message like this (Figure 2):

Figure 2
Let us go on with the example (Figure 3):

Figure 3
An integer input is requested with the (getint) function in the 46th line. It is checked that if the given value is different than zero in the 50th line. If it is zero, an alert will be printed and the function concludes. If it is not zero, division process will be done. This prevents errors during division process. Yet, if the user responds the (getint) function with ‘ESC’ button, error function will take place and print the message below:
Command: test
Enter an integer:*Cancel*
Error in function C:TEST
Error desc.:Function cancelled
(alert msg) function prints ‘nil’ and accepts a new line constant ( \n ) in the error message. So, you can write messages in multiple lines.
(exit) and (quit) functions:
Both functions do the same job; exiting from the programme. It is an unwanted method to end the programme for the programmer. If you still want to use it, our error handling function will work (Figure 4).

Figure 4
If you run the programme and input ‘0’ for the requested value, (exit) and our error handling function will run:
Command: test
Enter an integer:0
Error in function C:TEST
Error desc.:quit / exit abort
That is all for today. Bye.
Quote of the day: Training a man means you have trained one person but, training a woman means you have trained a whole family.
Viewed 2,433 times so far... This week: 30 Today: 3 Latest: 5 July 2009, 4:42Post Tags:
Related Posts
Popular
- Hip tip: Increasing view resolution with VIEWRES system variable
07/03/2009 04:39 am
7 Comments - Sirince – IZMIR
07/02/2009 11:02 am
1 Comment - Visual LISP: Programming user interfaces with OpenDCL
07/01/2009 10:15 pm
10 Comments - 3D Modeling 7: EXTRUDE
06/30/2009 02:14 pm
10 Comments - Ask DailyAutoCAD: Which Notebook to Buy?
06/30/2009 12:17 pm
1 Comment
Featured Articles
- AutoCAD 2009 Update 3 Released
- Speed Up As AutoCAD 2009 Ribbon Menu Helps You!
- MEP Analysis Extension for AutoCAD MEP extended to March 31, 2009
- Recap of AutoCAD-related technologies on Autodesk Labs
- Technology Preview of MEP Analysis Extension extended to 12/31/08
- Autodesk Labs: Forward and Backward utility for AutoCAD
|
