fix backtrace printed when cannot get lock.
change lock error handling code so exceptions have useful info and
exception handling in one place.
add test case for when cannot get lock.
#!/bin/sh
hg
hg -q
hg help
hg -q help
hg add -h
hg add --skjdfks
hg help diff
hg help status
hg -q help status
hg help foo
hg skjdfks
exit 0