Python: Catching and throwing exceptions