- 重要な情報
- はじめに
- 用語集
- ガイド
- エージェント
- インテグレーション
- OpenTelemetry
- 開発者
- API
- CoScreen
- アプリ内
- Service Management
- インフラストラクチャー
- アプリケーションパフォーマンス
- 継続的インテグレーション
- ログ管理
- セキュリティ
- UX モニタリング
- 管理
ID: python-best-practices/finally-no-break-continue-return
言語: Python
重大度: 警告
カテゴリー: ベストプラクティス
finally
ブロックの中で return
、break
、continue
を使用すると、try
、else
、except
ブロックでスローされた例外の伝播が停止し、return ステートメントは無視されます。
try:
client_obj.get_url(url)
except (URLError, ValueError):
client_obj.remove_url(url)
except SocketTimeout:
client_obj.handle_url_timeout(url)
finally:
break # finally ブロックの break を避けます
try:
client_obj.get_url(url)
except (URLError, ValueError):
client_obj.remove_url(url)
except SocketTimeout:
client_obj.handle_url_timeout(url)
finally:
return 0 # finally ブロックの return を避けます
try:
client_obj.get_url(url)
except (URLError, ValueError):
client_obj.remove_url(url)
except SocketTimeout:
client_obj.handle_url_timeout(url)
finally:
continue # finally ブロックの continue を避けます
try:
client_obj.get_url(url)
except (URLError, ValueError):
client_obj.remove_url(url)
except SocketTimeout:
client_obj.handle_url_timeout(url)
finally:
print("cleanup the mess")