FWIW .. using the built in *error* function is a bit simpler like so ( also don't forget to localize it (defun c:elp (/ *error* ... )
(defun c:elp (/ *error* deriv ent ent-sel js obj_curv old_orth old_osmd old_snp param pt_sel pt_tmp
p_from p_to)
(defun *error* (msg)
(and old_osmd (setvar "osmode" old_osmd))
(and old_orth (setvar "orthomode" old_orth))
(and old_snp (setvar "snapang" old_snp))
(if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
(princ (strcat "\nError: " msg))
)
(princ)
)
(princ "\nRaise a perpendicular to: ")
(while (not (setq js (ssget "_+.:E:S" '((0 . "*LINE,ARC,CIRCLE,ELLIPSE,RAY"))))))
(setq ent-sel (ssnamex js 0)
ent (cadar ent-sel)
pt_sel (cadar (cdddar ent-sel))
obj_curv (vlax-ename->vla-object ent)
)
(cond ((member (vlax-get-property obj_curv 'objectname)
'("AcDbPolyline" "AcDb2dPolyline" "AcDbLine" "AcDbArc"
"AcDbCircle" "AcDbEllipse" "AcDbSpline" "AcDbRay"
"AcDbXline"
)
)
(setq old_osmd (getvar "osmode")
old_snp (getvar "snapang")
old_orth (getvar "orthomode")
pt_sel (vlax-curve-getclosestpointto obj_curv pt_sel)
param (vlax-curve-getparamatpoint obj_curv pt_sel)
deriv (vlax-curve-getfirstderiv obj_curv param)
)
(setq pt_tmp (polar pt_sel (+ (atan (cadr deriv) (car deriv)) (/ pi 2)) 100.0))
(setvar "snapang" (angle (trans pt_sel 0 1) (trans pt_tmp 0 1)))
(setvar "orthomode" 1)
(if (null (setq p_from (getpoint "\nFrom point <lastpoint>: ")))
(setq p_from (trans pt_sel 0 1))
)
(setvar "osmode" 0)
(initget 9)
(setq p_to (getpoint p_from "\nTo point : "))
(command "_.line" p_from p_to "")
(setvar "osmode" old_osmd)
(setvar "orthomode" old_orth)
(setvar "snapang" old_snp)
)
(t (princ "\nInvalid object!"))
)
(princ)
)
(vl-load-com)