c++-gtk-utils
Public Member Functions | Public Attributes | List of all members
Cgu::SharedPtrError< T > Class Template Reference

This is an exception struct thrown as an alternative to deleting a managed object when internal memory allocation for SharedPtr or SharedLockPtr fails in their reset() method or in their constructor which takes a pointer. More...

#include <c++-gtk-utils/shared_ptr.h>

Inheritance diagram for Cgu::SharedPtrError< T >:

Public Member Functions

virtual const char * what () const throw ()
 
 SharedPtrError (T *p)
 

Public Attributes

T * obj
 

Detailed Description

template<class T>
class Cgu::SharedPtrError< T >

This is an exception struct thrown as an alternative to deleting a managed object when internal memory allocation for SharedPtr or SharedLockPtr fails in their reset() method or in their constructor which takes a pointer.

See also
SharedPtr SharedLockPtr SharedPtrAllocFail

This is an exception struct thrown as an alternative to deleting a managed object when SharedPtr<T>::SharedPtr(T*), SharedLockPtr<T>::SharedLockPtr(T*), SharedPtr<T>::reset(T*) or SharedLockPtr<T>::reset(T*), would otherwise throw std::bad_alloc. To make those methods do that, Cgu::SharedPtrAllocFail::leave is passed as their second argument.

If the exception is thrown, the struct has a member 'obj' of type T*, which is a pointer to the object originally passed to those methods, so the user can deal with it appropriately. This enables the result of the new expression to be passed directly as the argument to those methods without giving rise to a resource leak, as in:

using namespace Cgu;
SharedPtr<T> s; // doesn't throw
try {
s.reset(new T, SharedPtrAllocFail::leave); // both T allocation and reset() might throw
}
catch (std::bad_alloc&) {
...
}
catch (SharedPtrError<T>& e) {
e.obj->do_something();
...
}
...

As above, a catch block will need to deal with std::bad_alloc (if the call to the new expression when creating the T object fails) as well as SharedPtrError (if the call to the new expression in the reset() method fails after a valid T object has been constructed).

Constructor & Destructor Documentation

◆ SharedPtrError()

template<class T >
Cgu::SharedPtrError< T >::SharedPtrError ( T *  p)
inline

Member Function Documentation

◆ what()

template<class T >
virtual const char* Cgu::SharedPtrError< T >::what ( ) const
throw (
)
inlinevirtual

Member Data Documentation

◆ obj

template<class T >
T* Cgu::SharedPtrError< T >::obj

The documentation for this class was generated from the following file:
Cgu::SharedPtrError
This is an exception struct thrown as an alternative to deleting a managed object when internal memor...
Definition: shared_ptr.h:113
Cgu
Definition: application.h:44
Cgu::SharedPtrAllocFail::leave
@ leave
Definition: shared_ptr.h:129
Cgu::SharedPtrError::obj
T * obj
Definition: shared_ptr.h:114
Cgu::SharedPtr
This is a smart pointer for managing the lifetime of objects allocated on freestore.
Definition: shared_ptr.h:211
Cgu::SharedPtr::reset
void reset(T *ptr=0)
Definition: shared_ptr.h:346