Closed mdavidsaver closed 8 years ago
oops, push the wrong branch
My preference is for std::invalid_argument. It's logically more correct, as no allocation might have been performed. If the buffer is allocated with new[] or some similar mechanism it will (usually, unless exceptions are disabled) throw the bad_alloc.If you allocate with malloc, I would say that the client code should check the pointer and throw the bad_alloc. The case when a null pointer is used (e.g. if it's initialised to null and never assigned to with the result of a allocation) will then return invalid_argument .
Changed to invalid_argument. Unless there are further objections I'll merge this on Monday.
Check for allocation failure in ctors and add const qualifier where possible. Also document that externally provided buffers will be passed to free() (so can't use new[]).