| 23 | }; |
| 24 | |
| 25 | int main() |
| 26 | { |
| 27 | std::cout << std::boolalpha |
| 28 | << "may_throw() noexcept? " << noexcept(may_throw()) << std::endl |
| 29 | << "no_throw() noexcept? " << noexcept(no_throw()) << std::endl |
| 30 | << "lmay_throw() noexcept? " << noexcept(non_block_throw()) << std::endl |
| 31 | << "lno_throw() noexcept? " << noexcept(block_throw()) << std::endl; |
| 32 | |
| 33 | try { |
| 34 | may_throw(); |
| 35 | } catch (...) { |
| 36 | std::cout << "捕获异常, 来自 my_throw()" << std::endl; |
| 37 | } |
| 38 | |
| 39 | try { |
| 40 | non_block_throw(); |
| 41 | } catch (...) { |
| 42 | std::cout << "捕获异常, 来自 non_block_throw()" << std::endl; |
| 43 | } |
| 44 | |
| 45 | try { |
| 46 | block_throw(); |
| 47 | } catch (...) { |
| 48 | std::cout << "捕获异常, 来自 block_throw()" << std::endl; |
| 49 | } |
| 50 | } |