名前空間
変種
操作

throw expression

提供: cppreference.com
< cpp‎ | language

 
 
C + +言語
一般的なトピック
Original:
General topics
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
フロー制御
Original:
Flow control
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
条件付き実行文
Original:
Conditional execution statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
繰り返し文
Original:
Iteration statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
文をジャンプします
Original:
Jump statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
機能します
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
関数の宣言
ラムダ関数の宣言
関数テンプレート
の歴史。インライン指定
例外仕様 (廃止予定)
noexcept指定子 (C++11)
例外
Original:
Exceptions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
式を投げる
名前空間
Original:
Namespaces
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
タイプ
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
decltype specifier (C++11)
指定子
Original:
Specifiers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
CV指定
貯蔵期間指定
constexprの指定子 (C++11)
自動指定 (C++11)
alignas指定子 (C++11)
初期化
Original:
Initialization
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
リテラル
Original:
Literals
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Original:
Expressions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
代替表現
ユーティリティ
Original:
Utilities
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
タイプ
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
typedef declaration
型の別名宣言 (C++11)
属性 (C++11)
キャストします
Original:
Casts
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
暗黙の型変換
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
Cスタイルキャストと機能
メモリの割り当て
Original:
Memory allocation
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
クラス
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
クラス固有の機能特性
Original:
Class-specific function properties
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
明示 (C++11)
静的
特殊なメンバ関数
Original:
Special member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
テンプレート
Original:
Templates
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
クラステンプレート
関数テンプレート
テンプレートの特殊化
パラメーターパック (C++11)
その他
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
インラインアセンブリ
 
誤った状態を通知し、エラーハンドラを実行.
Original:
Signals an erroneous condition and executes an error handler.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

目次

[編集] 構文

throw expression (1)
throw (2)

[編集] 説明

と'キャッチ(例外ハンドラ)tryブロックを参照してください
1)
throw式はexpressionと同じタイプ(CV-修飾子を指定して削除され、型がTの配列から変換Tへのポインタに、関数から必要に応じて、Tを返す関数へのポインタにTを返す)と、不特定のストレージに一時オブジェクトを構築しますと、関数の引数や戻り値と同様に、expressionからそれを初期化する関数のパラメータまたはreturn式の引数(可能であれば、すなわちコピー省略し、移動の建設が行われる)から初期化されます。例外オブジェクトは最後のcatch句が完了するまで、または参照は、このオブジェクトが破棄されていることを最後まで持続std::exception_ptr.
Original:
The throw expression constructs a temporary object in unspecified storage, with the same type as expression (with cv-qualifiers removed and the type converted from array of T to pointer to T and from function returning T to pointer to function returning T, as necessary), and initializes it from expression in the same manner a function arguments or return values are initialized from the function parameters or the argument of a return expression (i.e. copy elision and move construction take place if possible). The exception object persists until the last catch clause completes or until the last std::exception_ptr that references this object is destroyed.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
例外オブジェクトが構築されると、関連付けられているtryブロックのパラメータが一致するものを見つけるためにスローcatchと比較され、その時点でexpressionブロックの先頭に到達するまで、制御フローが後方(呼び出しスタックアップ)動作します。一致が見つからない場合は、制御フローは、というように、次のtryブロックまでスタックをアンワインドし続けています。一致が見つかった場合は、制御フロー正常に実行されますマッチングcatchブロック(例外ハンドラ)へジャンプします.
Original:
Once the exception object is constructed, the control flow works backwards (up the call stack) until it reaches the start of a try block, at which point the parameters of the associated catch blocks are compared with the thrown expression to find a match. If no match is found, the control flow continues to unwind the stack until the next try block, and so on. If a match is found, the control flow jumps to the matching catch block (the exception handler), which executes normally.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
対応するtryブロック建設の逆の順序で、入力された以降構築した。例外はコンストラクタからスローされた場合、デストラクタはすべて、完全に構築された非静的非変異体のメンバと基底クラスに対して呼び出されています。このプロセスは、呼び出されたスタック巻き戻しを..
Original:
As the control flow moves up the call stack, destructors are invoked for all objects with '
自動記憶域期間
Original:
automatic storage duration
The text has been machine-translated via [http://translate.google.com Google Translate].
You can help to correct and verify the translation. Click [http://en.cppreference.com/w/Cppreference:MachineTranslations here] for instructions.
</div>
constructed since the corresponding try-block was entered, in reverse order of construction. If an exception is thrown from a constructor, destructors are called for all fully-constructed non-static non-variant members and base classes. This process is called stack unwinding.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
2)
オペランドなし投げ込み式は唯一の(そうでなければ、使用している場合、それがstd::terminate呼び出し)catchブロックの内部で使用することができる。これは、既存の例外オブジェクトを再利用して、catchブロックの実行を放棄し、コールスタックアップに一致する次のcatch節(ただし、同じtryブロックの後に別のcatch節に)に制御を渡します:新しいオブジェクトが作成されません.
Original:
The throw-expression without an operand may only be used inside a catch block (it calls std::terminate if used otherwise). It abandons the execution of the catch block and passes control to the next matching catch clause up the call stack (but not to another catch clause after the same try block), reusing the existing exception object: no new objects are made.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
例外処理中に発生するエラーの処理のためにstd::terminatestd::unexpectedを参照してください。.
Original:
See std::terminate and std::unexpected for the handling of errors that arise during exception handling.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] 用法

投げ込み式は実行スタックアップ、任意の理由(std::longjmpに似ている)のためのコードの任意のブロックに制御を転送するために使用することができますが、その意図された用法は、エラー処理です.
Original:
While throw-expression can be used to transfer control to an arbitrary block of code up the execution stack, for arbitrary reasons (similar to std::longjmp), its intended usage is error handling.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] エラー処理

例外がスローされると、 "エラー"は一般的に博士Dobbの</ ref>の中でのみ、次の引用エラー: <ref> タグに対応する </ref> タグが不足しています[1]:
Original:
{{{2}}}
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
#障害の不変条件を確立する
Original:
# Failures to establish invariants
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
#障害事後条件を満たすために
Original:
# Failures to meet the postconditions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
#失敗は呼び出し側の前提条件を満たすために
Original:
# Failures to meet the preconditions of the caller
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
特に、これはコンストラクタとほとんどの演算子の失敗が例外をスローすることによって報告されるべきであることを意味します.
Original:
In particular, this implies that the failures of constructors and most operators should be reported by throwing exceptions.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] 例外安全性

エラー条件が関数によって報告された後、追加の保証は、プログラムの状態に関して提供されてもよい。例外保証のうち、次の4つのレベルは、一般的に引用エラー: <ref> タグに対応する </ref> タグが不足しています[2][3], which are strict supersets of each other:
Original:
{{{2}}}
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Nothrow(またはnofail)例外保証 - 関数は例外をスローすることはありません.
Original:
# Nothrow (or nofail) exception guarantee -- the function never throws exceptions.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
強い例外保証 - 関数が例外をスローした場合、プログラムの状態は単なる関数呼び出し前の状態にロールバックされます.
Original:
# Strong exception guarantee -- If the function throws an exception, the state of the program is rolled back to the state just before the function call.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
基本例外保証 - 関数が例外をスローした場合、プログラムが有効な状態である。それはクリーンアップを必要とするかもしれませんが、すべての不変量はそのままです.
Original:
# Basic exception guarantee -- If the function throws an exception, the program is in a valid state. It may require cleanup, but all invariants are intact.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
も例外保証 - 関数が例外をスローした場合、プログラムが有効な状態ではないかもしれません:リソースリーク、メモリ破壊、または他の不変破壊エラーが発生した可能性があります.
Original:
# No exception guarantee -- If the function throws an exception, the program may not be in a valid state: resource leaks, memory corruption, or other invariant-destroying errors may have occurred.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] Exceptionオブジェクト

voidへの任意の完全型とcvポインタのオブジェクトが例外オブジェクトとしてスローされるかもしれませんが、すべての標準ライブラリ関数は、値によって匿名の一時オブジェクトをスローし、それらのオブジェクトの種類がstd::exceptionから(直接または間接的に)導出されます。ユーザー定義の例外は、通常、このパターンに従ってください。引用エラー: <ref> タグに対応する </ref> タグが不足しています[4]
Original:
{{{2}}}
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
例外オブジェクトとスライスオブジェクトの不必要なコピーを避けるためには、catch節のベストプラクティスは、参照によってキャッチすることです。引用エラー: <ref> タグに対応する </ref> タグが不足しています[5][6]
Original:
{{{2}}}
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] キーワード

throw

[編集]

[編集] 参照

  1. H.Sutter, A. Alexandrescu (2004), "C++ Coding Standards", Item 70
  2. H. Sutter (2000) "Exceptional C++"
  3. D. Abrahams (2001) "Exception Safety in Generic Components"
  4. M. Cline, C++FAQ Lite 17.11
  5. M. Cline, C++FAQ Lite 17.12
  6. H.Sutter, A. Alexandrescu (2004) "C++ Coding Standards" Item 73
Original:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] も参照してください