Improve exception handling

* Invalid.*Error can now be given parameters describing specialized context of the error
* fixed the bug of catching TypeError too often
Merge branch 'login' into exception_handling