On Thu, 13 Oct 2016 15:06:25 +0100, Daiyue Weng wrote:

> I know that such try-catch usage is generally a bad practice, since it
> can't locate the root of the exceptions.
> I am wondering how to correct the code above

Either identify the specific exceptions you're expecting, or if you're
interested in "any error", use "except StandardError". That will catch
"errors" but won't catch e.g. KeyboardInterrupt or SystemExit.

Trying to further narrow the set of possible exceptions is often
impossible considering the use of duck typing.


Reply via email to