python - Continue loop after exception is excepted -
i have loop try...except
:
try: sqlcommand in sqlcommands: cursor.execute(sqlcommand) except psycopg2.programmingerror err: print "programming error spotted. message -->" print err
this loop creates tables in sql. want here if there table(programming exception generated), print message under exception continue loop, not stop it. can it?
you need change order of try
statement:
for sqlcommand in sqlcommands: try: cursor.execute(sqlcommand) except psycopg2.programmingerror err: print "programming error spotted. message -->" print err
in case while iterating loop, each query try except
block run , if error found main for
loop iteration still working.
Comments
Post a Comment