C++ Exception Library - bad_weak_ptr



Description

It is a bad weak pointer.

Declaration

Following is the declaration for std::bad_weak_ptr.

class bad_weak_ptr: public exception;

C++11

class bad_weak_ptr: public exception;

Parameters

none

Return Value

none

Exceptions

No-throw guarantee − no members throw exceptions.

Example

In below example for std::bad_typeid.

#include <memory>
#include <iostream>
int main() {
   std::shared_ptr<int> p1(new int(42));
   std::weak_ptr<int> wp(p1);
   p1.reset();
   try {
      std::shared_ptr<int> p2(wp);
   } catch(const std::bad_weak_ptr& e) {
      std::cout << e.what() << '\n';
   }
}

The sample output should be like this −

bad_weak_ptr
exception.htm
Advertisements