Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::system_error

      From cppreference.com
      <cpp‎ |error
       
       
      Utilities library
       
      Diagnostics library
       
       
      Defined in header<system_error>
      class system_error;
      (since C++11)

      std::system_error is the type of the exception thrown by various library functions (typically the functions that interface with the OS facilities, e.g. the constructor ofstd::thread) when the exception has an associatedstd::error_code, which may be reported.

      std-system error-inheritance.svg

      Contents

      [edit]Member functions

      constructs thesystem_error object
      (public member function)[edit]
      replaces thesystem_error object
      (public member function)[edit]
      returns error code
      (public member function)[edit]
      [virtual]
      returns an explanatory string
      (virtual public member function)[edit]

      Inherited fromstd::exception

      Member functions

      [virtual]
      destroys the exception object
      (virtual public member function ofstd::exception)[edit]
      [virtual]
      returns an explanatory string
      (virtual public member function ofstd::exception)[edit]

      [edit]Example

      Run this code
      #include <iostream>#include <system_error>#include <thread> int main(){try{std::thread().detach();// attempt to detach a non-thread}catch(const std::system_error& e){std::cout<<"Caught system_error with code ""["<< e.code()<<"] meaning ""["<< e.what()<<"]\n";}}

      Possible output:

      Caught system_error with code [generic:22] meaning [Invalid argument]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/error/system_error&oldid=157563"

      [8]ページ先頭

      ©2009-2025 Movatter.jp