Try-except clause with an empty except code [duplicate] Try-except clause with an empty except code [duplicate] python python

Try-except clause with an empty except code [duplicate]


try:    do_something()except:    pass

You will use the pass statement.

The pass statement does nothing. It can be used when a statement is required syntactically but the program requires no action.


Use pass:

try:    foo()except:     pass

A pass is just a placeholder for nothing, it just passes along to prevent SyntaxErrors.


try:  doSomething()except:   pass

or you can use

try:  doSomething()except Exception:   pass