Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::system_error::system_error

      From cppreference.com
      <cpp‎ |error‎ |system error
       
       
      Utilities library
       
      Diagnostics library
       
       
      system_error(std::error_code ec);
      (1)(since C++11)
      system_error(std::error_code ec,conststd::string& what_arg);
      (2)(since C++11)
      system_error(std::error_code ec,constchar* what_arg);
      (2)(since C++11)
      system_error(int ev,conststd::error_category& ecat);
      (3)(since C++11)
      system_error(int ev,conststd::error_category& ecat,
                   conststd::string& what_arg);
      (4)(since C++11)
      system_error(int ev,conststd::error_category& ecat,
                   constchar* what_arg);
      (4)(since C++11)
      system_error(const system_error& other)noexcept;
      (5)(since C++11)

      Constructs new system error object.

      1) Constructs with error codeec.
      2) Constructs with error codeec and explanation stringwhat_arg. The string returned bywhat() is guaranteed to containwhat_arg as a substring.
      3) Constructs with underlying error codeev and associated error categoryecat.
      4) Constructs with underlying error codeev, associated error categoryecat and explanatory stringwhat_arg. The string returned bywhat() is guaranteed to containwhat_arg as a substring (assuming that it doesn't contain an embedded null character).
      5) Copy constructor. Initializes the contents with those ofother. If*this andother both have dynamic typestd::system_error thenstd::strcmp(what(), other.what())==0.

      [edit]Parameters

      ec - error code
      ev - underlying error code in the enumeration associated withecat
      ecat - the category of error
      what_arg - explanatory string
      other - anothersystem_error to copy

      [edit]Example

      Demonstrates how to create asystem_error exception from anerrno value.

      Run this code
      #include <iostream>#include <system_error> int main(){try{throwstd::system_error(EDOM,std::generic_category(),"FIX ME");}catch(conststd::system_error& ex){std::cout<<"code:    ["<< ex.code()<<"]\n""message: ["<< ex.code().message()<<"]\n""what:    ["<< ex.what()<<"]\n";}}

      Possible output:

      code:    [generic:33]message: [Numerical argument out of domain]what:    [FIX ME: Numerical argument out of domain]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/error/system_error/system_error&oldid=160410"

      [8]ページ先頭

      ©2009-2025 Movatter.jp