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

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

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

Inheritance diagram for Cgu::SharedHandleError< T >:

Public Member Functions

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

Public Attributes

obj
 

Detailed Description

template<class T>
class Cgu::SharedHandleError< T >

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

See also
SharedHandle SharedLockHandle SharedHandleAllocFail

This is an exception struct thrown as an alternative to deleting a managed object when SharedHandle<T>::SharedHandle(T), SharedLockHandle<T>::SharedLockHandle(T), SharedHandle<T>::reset(T) or SharedLockHandle<T>::reset(T) would otherwise throw std::bad_alloc. To make those methods do that, Cgu::SharedHandleAllocFail::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 or array 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;
SharedHandle<T*> s; // doesn't throw
try {
s.reset(new T[2], SharedHandleAllocFail::leave); // both T allocation and reset() might throw
}
catch (std::bad_alloc&) {
...
}
e.obj[0].do_something();
e.obj[1].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 SharedHandleError (if the call to the new expression in the reset() method fails after a valid T object has been constructed).

Constructor & Destructor Documentation

◆ SharedHandleError()

template<class T >
Cgu::SharedHandleError< T >::SharedHandleError ( p)
inline

Member Function Documentation

◆ what()

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

Member Data Documentation

◆ obj

template<class T >
T Cgu::SharedHandleError< T >::obj

The documentation for this class was generated from the following file:
Cgu
Definition: application.h:45
Cgu::SharedHandleError
This is an exception struct thrown as an alternative to deleting a managed object when internal memor...
Definition: shared_handle.h:484
Cgu::SharedHandle::reset
void reset(T ptr=0)
Definition: shared_handle.h:655
Cgu::SharedHandleAllocFail::leave
@ leave
Definition: shared_handle.h:500
Cgu::SharedHandle
This is a generic class for managing the lifetime of objects allocated on freestore.
Definition: shared_handle.h:410
Cgu::SharedHandleError::obj
T obj
Definition: shared_handle.h:485