Better error handling in Python