here is the code with proper error handling and @BIGAL revised getpoint:
(defun c:MLeaderWBlname( / trap1 olderr osnp tm tagname ptms ss ensel obj obj1 ifobj nam)
(defun trap1 ( msg );define error trap
(setq *error* olderr);restore *error* symbol
(SETVAR "OSMODE" osnp);reset OSMODE
(princ)
)
(setq olderr *error*); assign current function defintion held by the *error* symbol to a local variable - olderr
(setq *error* trap1); pointing the *error* symbol to new function definition - trap1
(setq osnp (getvar "OSMODE"))
(setvar "OSMODE" 0)
(setq tm (getvar "TILEMODE"))
(setq ifobj 0)
(while (getpoint "\nSelect object in paper space,select start point of MLeader,exit with ENTER/ESC/Right Click") ;;get point in paper space on the target object
(if (= tm 0);if in paper space
(progn
(command "._MSPACE")
(setq ptms (cadr (grread t)));;get the point where the cursor is on the target object in model space
(if (=(setq ss (ssget ptms)) nil) ;;selction set of the object crossing the ptms point
(progn
(alert "There is no selection set please run again")
(setq ifobj 0)
(command "._PSPACE")
);progn
(progn
(command "._PSPACE")
(setq obj(ssname ss 0))
(setq ifobj 1)
);progn
);if
);progn
(progn ;in model space
(setq ensel (entsel "\nSelect Block: ")) ;select the block object to copy
(setq obj (car ensel)) ;set the block object to varaible
(setq ifobj 1)
);progn
);if
(if (= ifobj 1) ;; check if there is a selection set
(progn
(if (= (cdr (assoc 0 (entget obj))) "INSERT");; check if selected object is block
(progn
(setq obj1 (vlax-ename->vla-object obj))
(setq nam
(vlax-get-property obj1
(if (vlax-property-available-p obj1 'effectivename)
'effectivename
'name
)
)
)
(command "_mleader" "H" pause pause nam)
(setq ifobj 0)
);progn
(alert "Not a Block")
);if
);progn
(alert "Not a Block")
);end if
);end while
(setq *error* olderr); restore *error* symbol
(command "._PSPACE")
(SETVAR "OSMODE" osnp)
(princ)
)