proper python exception handling