Fix exception-related PEP8 issues

This changeset resolves 3 PEP8 issues: It addresses the following
exception-related PEP8 violation:
- W602 deprecated form of raising exception

I'll lower the violation threshold after #5925 and #6044 are merged.