How can I stop error messages?

How can I stop error messages?

saitoib
Advocate Advocate
1,852 Views
5 Replies
Message 1 of 6

How can I stop error messages?

saitoib
Advocate
Advocate

Hello everyone

I'm running a lisp program with a while statement, and when I press esc to abort, I get an "error: Function Cancelled" message, is there any way to suppress this?

 

Saitoib
0 Likes
Accepted solutions (2)
1,853 Views
5 Replies
Replies (5)
Message 2 of 6

hak_vz
Advisor
Advisor

Yesterday you have asked about local functions. Here is a general code for local *error* function that suppresses showing error on hitting esc key, but that will  show error code in case on some other error

 

 

 

(defun c:somefunction ( / *error* .....)
;local error function 
;copy this to your code
 (defun *error* (msg)
	  (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*"))
	       (setvar 'cmdecho 1)
	       (princ (strcat "\nOops an Error : ( " msg " ) occurred."))
	  ) ;_ end of if
	  (princ)
     ) ;_ end of defun

...
....

);end of somefunction 

 

 

 

Modification to *error*  (must be written that way with *) function depends further on what is inside code but this would have to work.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 3 of 6

Moshe-A
Mentor
Mentor
Accepted solution

@saitoib hi,

 

of course you can 😀 all you have to do is to define your own error handler function (see bellow) which gets automatically called when an error occurs and pressing ESC is considered error. in error handler function you do all the cleaning needed (like restore sysvars values) to exist nice and clean.

 

after you implement an error handler consider to add a clean exist from while loop by accepting enter to (getXXX) function or use (getkword) function to accept "eXit" option.

 

enjoy

moshe

 

 

(defun c:test ()
 (setq *error* error-handler) ; assign your own error handler

 ; your command code
 ; ....

 (setq *error* nil) ; restore to autolisp error handler
 (princ)
)

(defun error-handler (msg)
 (if (not (wcmatch (strcase msg t) "*break*,*cancel*,*exit*"))
  (princ (strcat "\nError: " msg))
 )

 ; clean up, restore sysvars values
 ; ......

 (setq *error* nil)
 (princ)
)

 

0 Likes
Message 4 of 6

hak_vz
Advisor
Advisor
Accepted solution

Here you have good explanation how to write error handler

Take care to localize *error* symbol.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 5 of 6

diagodose2009
Collaborator
Collaborator

You can localize the error in fast mode and automatic,(even inside .VLX) or inside..Fas

You detokenize your source-ascii to format _jcaro10.lsp

You search the error with NotePad.exe and CTRL+F

Select the Horizontal alignment(long-red-line):
Enter the vertical exaggeration <1>:
Select one or more entities to get ContoursLayer/s:
Select objects: 0 found
Select objects:

dfn_getlayname=[((0 . POLYLINE) (8 . Contour))]
; error: bad argument type: safearrayp nil

Command: (princ setmypid)
C113"C113"

After you got the error/s, then you type at Command-line.

 

 

 

 

 

(princ setmypid)
(princ getmypid)

 

 

 

 

 

 

 

 

0 Likes
Message 6 of 6

saitoib
Advocate
Advocate

Everyone

Thank you again and again.
I have learned a lot.

Saitoib
0 Likes