On Wed, Feb 20, 2019 at 1:59 AM songbird <songb...@anthive.com> wrote:
>
> MRAB wrote:
> ...
> > Don't use a bare except, it'll catch _any_ exception.
>
>   that's ok with this code IMO, but i see your point.
>

Not really, no. It means that ANY bug (barring an outright syntax
error) inside the try block will silently move you on to the next
check, possibly after printing out the message. Suppose you misspelled
"return".


    result = re.search("^/(tmp)|(var)|(usr)|(opt)|(home)", sysprobetmp)
    try:
        print ("Result : -->" + result.group(0) + "<--\n")

        retun ("posix")
    except:
        pass

It'll print out the result, bomb with a NameError, swallow the
NameError, and silently move on. The *only* times you should use a
bare except clause are with a "raise" inside it, or with a
log-and-return boundary marker (where "inner" code isn't allowed to
crash "outer" code, eg in a web app) - and the "log" part is
absolutely essential.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to