python try except 0 -


i reading python code written while ago, , found this:

try:     # stuff except 0:     # exception handling stuff 

and i'm not sure except 0 means? have guesses: supposed catch nothing i.e. let exception propagate or sort of switch turn debugging mode on , off removing 0 catch everything.

can lend insight? google search yielded nothing...

thanks!

some sample code (by request):

            try:                 if logerrors:                     dbstuffer.setstatustoerror(prop_id, obj)                     db.commit()             except 0:                 traceback.print_exc() 

from understand, useful debugging purposes (catching type of exception)

in example 0 acts placeholder determine type of exception.

>>> try: ...   x = 5/1 + 4*a/3 ... except 0: ...   print 'error' ...  traceback (most recent call last):   file "<stdin>", line 2, in <module> nameerror: name 'a' not defined >>> try: ...   x = 5/0 + 4*a/3 ... except 0: ...   print 'error' ...  traceback (most recent call last):   file "<stdin>", line 2, in <module> zerodivisionerror: integer division or modulo 0 

in first case, exception nameerror , zerodivisionerror in second. 0 acts placeholder type of exception being caught.

>>> try: ...   print 'error' ... except: ...  keyboardinterrupt >>> try: ...   x = 5/0 + 4*a/3 ... except: ...   print 'error' ...  error 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -