C++例外伝搬と(C++標準規格に含まれる)C標準ライブラリの関係についてメモ。*1
- C標準ライブラリ関数からは例外throwを行わない。(noexcept指定がされているとみなしてよい)
- ただしユーザ定義関数のコールバックを行う標準ライブラリ関数は特例。
qsort,bsearch関数からは例外throwされるかもしれない。
C++11(N3337) 17.6.5.12/p3, 25.5/p4より一部引用。
3 Functions from the C standard library shall not throw exceptions190 except when such a function calls a program-supplied function that throws an exception.191
脚注190) That is, the C library functions can all be treated as if they are markednoexcept. This allows implementations to make performance optimizations based on the absence of exceptions at runtime.
脚注191) The functionsqsort()andbsearch()(25.5) meet this condition.
4 (snip)
[Note: Because the function argumentcompar()may throw an exception,bsearch()andqsort()are allowed to propagate the exception (17.6.5.12). -- end note]
See also: ISO C 7.10.5.
関連URL