Movatterモバイル変換
[0]ホーム
[Python-Dev] FW: Bare except clauses in PEP 348
Raymond Hettingerraymond.hettinger at verizon.net
Wed Aug 24 17:27:19 CEST 2005
Hey guys, don't give up your bare except clauses so easily.They are useful. And, if given the natural meaning of "catcheverything" and put in a natural position at the end of a suite, theirmeaning is plain and obvious. Remember beauty counts. I don't thinkthere would be similar temptation to eliminate a dangling else clauseand replace it with "else Everything". Nor would a final default casein a switch statement benefit from being written as "defaultEverything".The thought is that it is okay to have useful defaults. My whole issuewas that the PEP was choosing the wrong default. If we leave it alone,all is well. An empty except will continue to mean "catch everything",it will always appear at the end, its meaning will be obvious, andexisting working code won't break :-)On the occasions where you really intended to catch everything, do youreally want to go on an editing binge just to uglify the code tosomething like: try: ... except SomeException: ... except BaseException: ...It is more beautiful and clear as: try: ... except SomeException: ... except: ...To me, the latter is more attractive and is more obviously a catchall,just like an else-clause or a default-statement. It is a strong visualcue that at least one of the except clauses will always be triggered.In contrast, the first example makes you think twice about whether thefinal case really does get everything (sometimes implicit IS better thanexplicit).Raymond
More information about the Python-Devmailing list
[8]ページ先頭