AUTOSAR C++14 Rule A15-3-4
Catch-all (ellipsis and std::exception) handlers shall be used only in (a) main, (b) task main functions, (c) in functions that are supposed to isolate independent components and (d) when calling third-party code that uses exceptions not according to AUTOSAR C++14 guidelines
説明
ルール定義
Catch-all (ellipsis and std::exception) handlers shall be used only in (a) main, (b) task main functions, (c) in functions that are supposed to isolate independent components and (d) when calling third-party code that uses exceptions not according to AUTOSAR C++14 guidelines.
根拠
catch(std::exception) ブロックや catch(...) ブロックなどの catch-all ハンドラーは、さまざまなタイプの例外と一致します。このような catch-all ハンドラーを使用して例外を処理する場合は、発生した例外に関する詳細情報や固有情報を入手できません。このような catch-all ハンドラーは、発生した例外を処理するための有意義な対策を講じることができません。これらの catch-all ハンドラーが役立つのは、再び例外を発生させたり、アプリケーションを適切に終了したりすることによる予期せぬ例外の処理をする場合です。
catch-all ハンドラーが効果を発揮するのは特定の用途に対してであり、すべての関数に対して使用するのは非効率です。catch-all ハンドラーを使用する対象:
- main 関数 
- タスク main 関数 
- AUTOSAR C++14 ガイドラインに準拠していない可能性のあるサードパーティ関数を呼び出す関数 
- コードの独立したコンポーネントを分離するように設計された関数 
Polyspace 実装
Polyspace® は、以下のいずれにも当てはまらない場合、関数内の catch(std::exception) ブロックと catch(...) ブロックにフラグを設定します。
- 関数 - main()である。
- タスク main 関数である。 
- 例外で終了する可能性のある外部関数またはサードパーティ関数を呼び出す。 
Polyspace は関数 main() を検出します。関数をタスク main 関数として指定するには、以下のコンパイル オプションを使用します。
- -entry-points <name> 
- -cyclic-tasks <name> 
- -interrupts <name> 
トラブルシューティング
ルール違反が想定されるものの、Polyspace から報告されない場合は、コーディング規約違反が想定どおりに表示されない理由の診断を参照してください。
例
チェック情報
| グループ: Exception handling | 
| カテゴリ: Required、Non-automated | 
バージョン履歴
R2020b で導入