Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::bad_exception

      From cppreference.com
      <cpp‎ |error
       
       
      Utilities library
       
      Diagnostics library
       
       
      Defined in header<exception>
      class bad_exception:public exception

      std::bad_exception is the type of the exception thrown by the C++ runtime in the following situations:

      • Ifstd::exception_ptr stores a copy of the caught exception and if the copy constructor of the exception object caught bystd::current_exception throws an exception, the captured exception is an instance ofstd::bad_exception.
      (since C++11)
      • If adynamic exception specification is violated andstd::unexpected throws or rethrows an exception that still violates the exception specification, but the exception specification allowsstd::bad_exception,std::bad_exception is thrown.
      (until C++17)
      std-bad exception-inheritance.svg

      All member functions ofstd::bad_exception areconstexpr.

      (since C++26)

      Contents

      [edit]Member functions

      constructs thebad_exception object
      (public member function)
      copies the object
      (public member function)
      [virtual]
      returns the explanatory string
      (virtual public member function)

      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]Notes

      Feature-test macroValueStdFeature
      __cpp_lib_constexpr_exceptions202411L(C++26)constexpr for exception types

      [edit]Example

      Compiles only in C++14 or earlier modes (may issue warnings).

      Run this code
      #include <exception>#include <iostream>#include <stdexcept> void my_unexp(){throw;} void test()throw(std::bad_exception)// Dynamic exception specifications// are deprecated in C++11{throwstd::runtime_error("test");} int main(){std::set_unexpected(my_unexp);// Deprecated in C++11, removed in C++17 try{        test();}catch(const std::bad_exception& e){std::cerr<<"Caught "<< e.what()<<'\n';}}

      Possible output:

      Caught std::bad_exception
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/error/bad_exception&oldid=183009"

      [8]ページ先頭

      ©2009-2025 Movatter.jp