Our Friends: Leaflet Printing , Presented by: Talia Cad Software

Sign In

Subscribe

Subscribe to Daily Autocad.


Mar 19
Wednesday
AutoLISP, Autocad, Programming
Error 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
Table.1

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

Fig.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):

Fig.2
Figure 2

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

Fig.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).

Fig.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:42

Post Tags:

Post a Comment



All content and source © 2008 Daily Autocad | News Plus wordpress theme brought to you by Zidalgo.