Added more precise error handling

The error handlers now handle their specific exceptions instead of just
hoping the exception raised in the right type. I have not fully tested
them yet so I may be re-commiting a few more times until it works.