"NSolve seems to have problem to Find the solutions"
f[x_]:=Exp[x]−x−2;
NSolve[f[x]==0,x]

f[x_]:=Exp[x]−x−2;
Plot[f[xdum],{xdum,-2,2}]
sol1=FindRoot[f[x]==0,{x,-2}];
sol2=FindRoot[f[x]==0,{x,1}];
sol1=x/.sol1;
sol2=x/.sol2;
Print["sol1,sol2 = ",{sol1,sol2}]
Plot[f[xdum],{xdum,sol1-1,sol2+1}]

"NSolve fails to find solutoins"

f[x_]:=(1/x) Sin[x];
Plot[f[xdum],{xdum,-1.5Pi,1.5Pi}]
sol=NSolve[f[x]==0,{x}];
sol=x/.sol;
Print["sol = ",sol]

"But FindRoot find the solutions"
f[x_]:=(1/x) Sin[x];
Plot[f[xdum],{xdum,-1.5Pi,1.5Pi}]
sol1=FindRoot[f[x]==0,{x,-4}];
sol2=FindRoot[f[x]==0,{x,4}];
sol1=x/.sol1;
sol2=x/.sol2;
Print["sol1,sol2 = ",{sol1,sol2}]
Plot[f[xdum],{xdum,sol1-1,sol2+1}]

"NSolve works well for this function"
f[x_]:=Tan[π x]−x−6;
Plot[f[xdum],{xdum,0,2Pi}]
sol=NSolve[f[x]==0&&0<x<2Pi,x];
sol=x/.sol;
Print["sol = ",sol]