bypass error when using vla-get-name

bypass error when using vla-get-name

GeryKnee
Advocate Advocate
441 Views
4 Replies
Message 1 of 5

bypass error when using vla-get-name

GeryKnee
Advocate
Advocate

Hi,

I wrote the following

(defun Fn ( Obj / *error* RES)
;;
(defun *error* (errmsg)
(PRINC)
)
;;
(princ "FnSTART")
(Setq RES (vla-get-name Obj))
(princ ">FnEND")
RES
)
(defun c:cm nil
(princ "In")
(Fn nil)
(princ ">Out")
)

 

After a call to cm command i get :

In>FnSTART

 

I expepted :

In>FnSTART>FnEND>Out

 

That's because after error caused by passing a nil Obj value to Fn , the code doesn't continous bypassing the error.

How this could be done?

Thanks,

Sincerely,

Gery

 

0 Likes
Accepted solutions (1)
442 Views
4 Replies
Replies (4)
Message 2 of 5

komondormrex
Mentor
Mentor
Accepted solution

hey,

that way

 

(defun Fn ( Obj / RES)
	(princ "FnSTART>")
	(Setq RES (vl-catch-all-apply 'vla-get-name (list Obj)))
	(princ "FnEND>")
	RES
)
(defun c:cm nil
	(princ "In>")
	(Fn nil)
	(princ "Out")
	(princ)
)

 

Message 3 of 5

GeryKnee
Advocate
Advocate
Thank you very match for your hlp komondormrex
Sincearly,
Gery
0 Likes
Message 4 of 5

komondormrex
Mentor
Mentor

your welcome)

0 Likes
Message 5 of 5

ВeekeeCZ
Consultant
Consultant

Well, vl-catch-all-apply might prevent the code from falling into error, but if it fails, it returns the name of the error.

So, it is better to add vl-catch-all-error-p to determine whether the result is ok or it's the error..

 

(defun Fn ( Obj / RES)  ;; returns either name or nil if failed
  (if (not (vl-catch-all-error-p (Setq RES (vl-catch-all-apply 'vla-get-name (list Obj)))))
    RES)
  )

(defun c:cm nil
  (princ "In>")
  (if (setq name (Fn nil))
    (you are good to go)
    (get-name faild, so do somthing about it))
  (princ "Out")
  (princ)
  )

 

0 Likes