Wwx95 Posted June 17, 2016 Share Posted June 17, 2016 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. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 17, 2016 Share Posted June 17, 2016 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. Quote Link to comment Share on other sites More sharing options...
Wwx95 Posted June 17, 2016 Author Share Posted June 17, 2016 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?? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 17, 2016 Share Posted June 17, 2016 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. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted June 19, 2016 Share Posted June 19, 2016 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. Quote Link to comment Share on other sites More sharing options...
tombu Posted June 20, 2016 Share Posted June 20, 2016 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. Quote Link to comment Share on other sites More sharing options...
Wwx95 Posted June 21, 2016 Author Share Posted June 21, 2016 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 Quote Link to comment Share on other sites More sharing options...
Wwx95 Posted June 21, 2016 Author Share Posted June 21, 2016 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! Quote Link to comment Share on other sites More sharing options...
Wwx95 Posted June 21, 2016 Author Share Posted June 21, 2016 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. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted June 21, 2016 Share Posted June 21, 2016 Just post your problems please 1 at a time and others will help. Quote Link to comment Share on other sites More sharing options...
tombu Posted June 21, 2016 Share Posted June 21, 2016 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.