Revert "Revert "Merge pull request #859 from wvh/register_error_handler""

This reverts commit 2aa26fff04a98f2435e8e3015e92ef6108d3b485.