Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::error_condition

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

      std::error_condition holds a platform-independent value identifying an error condition. Likestd::error_code, it is uniquely identified by an integer value and astd::error_category, but unlikestd::error_code, the value is not platform-dependent.

      A typical implementation holds one integer data member (the value) and a pointer to anstd::error_category.

      Contents

      [edit]Member functions

      constructs anerror_condition
      (public member function)[edit]
      replaces the contents
      (public member function)[edit]
      replaces the contents
      (public member function)[edit]
      sets theerror_condition to value0 ingeneric_category
      (public member function)[edit]
      obtains the value of theerror_condition
      (public member function)[edit]
      obtains theerror_category for thiserror_condition
      (public member function)[edit]
      obtains the explanatory string
      (public member function)[edit]
      checks if the value is non-zero
      (public member function)[edit]

      [edit]Non-member functions

      (removed in C++20)(removed in C++20)(C++20)
      compareserror_conditions anderror_codes
      (function)[edit]

      [edit]Helper classes

      identifies an enumeration as anstd::error_condition
      (class template)[edit]
      hash support forstd::error_condition
      (class template specialization)[edit]

      [edit]Notes

      Thecomparison between astd::error_code and astd::error_condition is defined by their error categories. Notably, an error condition ofstd::generic_category may compare equal to an error code of a specific category (e.g.std::system_category), if they represent the same kind of error.

      Astd::errc value can be compared to an error code via implicit conversion tostd::error_condition.

      Run this code
      #include <cerrno>#include <iostream>#include <system_error>#include <Windows.h> int main(){std::error_code ec{ERROR_FILE_EXISTS,std::system_category()};    std::error_condition econd{EEXIST,std::generic_category()}; std::cout.setf(std::ios::boolalpha);std::cout<<(ec== econd)<<'\n';// typically truestd::cout<<(ec==std::errc::file_exists)<<'\n';// dittostd::cout<<(ec== make_error_code(std::errc::file_exists))<<'\n';// false:// different category}

      Possible output:

      truetruefalse

      [edit]See also

      (C++11)
      holds a platform-dependent error code
      (class)[edit]
      base class for error categories
      (class)[edit]
      creates an error condition for anerrc valuee
      (function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/error/error_condition&oldid=172315"

      [8]ページ先頭

      ©2009-2025 Movatter.jp