• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

    最終更新日時(UTC):
    が更新

    履歴 編集

    function template
    <exception>

    std::make_exception_ptr

    namespace std {
      template <class E>
      exception_ptr make_exception_ptr(E e) noexcept;
    }
    

    概要

    引数の例外オブジェクトを元にexception_ptrオブジェクトを生成する。

    効果

    try {
      throw e;
    } catch(...) {
      return current_exception();
    }
    

    戻り値

    例外オブジェクトeを指すexception_ptrオブジェクトを返す。

    例外

    投げない

    #include <iostream>
    #include <exception>
    #include <stdexcept>
    
    int main()
    {
      std::exception_ptr p = std::make_exception_ptr(std::runtime_error("error!!!"));
    
      try {
        std::rethrow_exception(p);
      }
      catch (std::runtime_error& e) {
        std::cout << e.what() << std::endl;
      }
    }
    

    出力

    error!!!
    

    バージョン

    言語

    • C++11

    処理系

    実装例

    template <class E>
    exception_ptr make_exception_ptr(E e) noexcept
    {
      try {
        throw e;
      }
      catch (...) {
        return current_exception();
      }
    }
    

    参照