bad_weak_ptr Class

Reports bad weak_ptr exception.

class bad_weak_ptr
    : public std::exception {
public:
    bad_weak_ptr();
    const char *what() throw();
    };

Remarks

The class describes an exception that can be thrown from the shared_ptr Class constructor that takes an argument of type weak_ptr Class. The member function what returns "tr1::bad_weak_ptr".

Example

 

// std_tr1__memory__bad_weak_ptr.cpp 
// compile with: /EHsc 
#include <memory> 
#include <iostream> 
 
int main() 
    { 
    std::tr1::weak_ptr<int> wp; 
 
     { 
    std::tr1::shared_ptr<int> sp(new int); 
    wp = sp; 
     } 
 
    try 
        { 
        std::tr1::shared_ptr<int> sp1(wp); // weak_ptr has expired 
        } 
    catch (const std::tr1::bad_weak_ptr&) 
        { 
        std::cout << "bad weak pointer" << std::endl; 
        } 
    catch (...) 
        { 
        std::cout << "unknown exception" << std::endl; 
        } 
 
    return (0); 
    } 
 

bad weak pointer

Requirements

Header: <memory>

Namespace: std::tr1

See Also

Reference

<memory> (TR1)

weak_ptr Class