Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
abruptly leaving try/except
#9
(Feb-19-2018, 09:32 PM)Gribouillis Wrote: What's wrong with using continue in the try...except statement? I'm doing this all the time
Nothing wrong just that pass is much more common in try...except.
There is a little difference:
continue will jump back to the top of the loop.
pass will continue processing.

So if look in Doc they always use pass when describing suppresses any of the specified exceptions.
So if using code example over.
from contextlib import suppress
import os
 
with suppress(OSError):
    info = os.lstat(file)
    print(info)
Writing the same as over with try...except then is pass as in Doc.
import os

try:
    info = os.lstat(file)
    print(info)
except OSError:
    pass
Reply


Messages In This Thread
abruptly leaving try/except - by Skaperen - Feb-18-2018, 03:20 AM
RE: abruptly leaving try/except - by snippsat - Feb-18-2018, 04:23 AM
RE: abruptly leaving try/except - by Skaperen - Feb-18-2018, 04:35 AM
RE: abruptly leaving try/except - by snippsat - Feb-18-2018, 05:29 PM
RE: abruptly leaving try/except - by Skaperen - Feb-19-2018, 07:05 AM
RE: abruptly leaving try/except - by Larz60+ - Feb-19-2018, 11:38 AM
RE: abruptly leaving try/except - by Gribouillis - Feb-19-2018, 09:32 PM
RE: abruptly leaving try/except - by Skaperen - Feb-20-2018, 03:23 AM
RE: abruptly leaving try/except - by snippsat - Feb-20-2018, 02:33 PM
RE: abruptly leaving try/except - by Skaperen - Feb-22-2018, 06:17 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020