better handling errors in python