dispatch: split global error handling out so it can be reused
We may want a similar error handling at worker.py. This patch extracts the
error handling logic to "callcatch" so it can be reused.
To run the tests, do:
cd tests/
python run-tests.py
See https://mercurial-scm.org/wiki/WritingTests for
more information on writing tests.