throw exception during error in python