Jump to content

Is error function necessary in every Autolisp routine?


Wwx95

Recommended Posts

Hi, do I need to add error function everytime when I write Autolisp code?And what's the difference between Error Trapping routine build into a function, and a Global Error Trapping function?? Thanks.

Link to comment
Share on other sites

Not absolutely necessary, it ultimately depends on whether you require the program to perform any caretaking operations and restore the original environment (if settings have been changed through the course of running the program) should an error occur.

Link to comment
Share on other sites

Not absolutely necessary, it ultimately depends on whether you require the program to perform any caretaking operations and restore the original environment (if settings have been changed through the course of running the program) should an error occur.

 

I see,so what's the difference between error built in function and global error function??

Link to comment
Share on other sites

what's the difference between error built in function and global error function??

 

The built-in error function will be evaluated if the *error* symbol has not been redefined, returning a standard error message e.g.:

_$ (rtos nil)
; error: bad argument type: numberp: nil

By 'global error function', I assume that you mean the case in which a program has globally redefined the *error* symbol to override the built-in error function for all globally evaluated programs/expressions (I would strongly advise against this practice). Here is an example:

_$ (defun *error* ( m ) (princ "\nMy Global Error Function.") (princ))
*ERROR*
_$ (rtos nil)

My Global Error Function.

Link to comment
Share on other sites

Error trapping can be as simple as checking object picked line v's pline, text is another is height in the style set to 0 or a value 2.5 this affects the text command, number of prompts.

Link to comment
Share on other sites

A routine that simply responds with the current layer name would not need an error function since there's always a current layer. As opposed to any routine that requires input, because it would have to account for improper input, no input, or simply hitting ESC which needs to respond either with another prompt or an error message.

Link to comment
Share on other sites

The built-in error function will be evaluated if the *error* symbol has not been redefined, returning a standard error message e.g.:

_$ (rtos nil)
; error: bad argument type: numberp: nil

By 'global error function', I assume that you mean the case in which a program has globally redefined the *error* symbol to override the built-in error function for all globally evaluated programs/expressions (I would strongly advise against this practice). Here is an example:

_$ (defun *error* ( m ) (princ "\nMy Global Error Function.") (princ))
*ERROR*
_$ (rtos nil)

My Global Error Function.

 

Ok,thanks,I think I have some basic knowledge about error function now:D

Link to comment
Share on other sites

A routine that simply responds with the current layer name would not need an error function since there's always a current layer. As opposed to any routine that requires input, because it would have to account for improper input, no input, or simply hitting ESC which needs to respond either with another prompt or an error message.

 

Sorry, but I don't quite understand your "current layer" and "routine that requires input"? What's the difference between them?Thanks!

Link to comment
Share on other sites

Error trapping can be as simple as checking object picked line v's pline, text is another is height in the style set to 0 or a value 2.5 this affects the text command, number of prompts.

 

Thanks man, I got so many problems,lol.

Link to comment
Share on other sites

A routine that simply responds with the current layer name would not need an error function since there's always a current layer. As opposed to any routine that requires input, because it would have to account for improper input, no input, or simply hitting ESC which needs to respond either with another prompt or an error message.

 

Sorry, but I don't quite understand your "current layer" and "routine that requires input"? What's the difference between them?Thanks!

 

The thread title is "Is error function necessary in every Autolisp routine?" I gave one example of one type that wouldn't need one and one that should always have one.

 

If you want to redefine *error* it's best to localize it so it doesn't affect any other code. There are also many ways of error trapping or error testing many types of input. Books have been written about this. Look at all the Similar Threads at the bottom of this thread.

 

If you post some code we could offer you suggestions.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...