if(!item)
throw std::invalid_argument("Collection::add(item)");
- insert_unique(items, name, RefPtr<typename RemoveConst<T>::Type>(item));
+ RefPtr<typename RemoveConst<T>::Type> ptr(item);
+ try
+ {
+ insert_unique(items, name, ptr);
+ }
+ catch(...)
+ {
+ // Avoid deleting the object
+ ptr.release();
+ throw;
+ }
}
/// Gets a typed object from the collection.
RefPtr<T> obj = new T;
Collection::ItemLoader<T> ldr(*obj, coll);
ldr.load(parser);
- // Collection::add will delete the object if it fails
- coll.add(name, obj.release());
+ coll.add(name, obj.get());
+ obj.release();
}
};