I'm in need of assistance. I have a function that allocates memory for the specified amount of elements, of the template type. However, I want the function to throw a bad_alloc exception if the allocation fails.
In the code above, I don't know if bad_alloc is thrown if the allocation of block fails. If bad_alloc isn't thrown automatically, how do I throw the exception? Do I need a try block?
If you want std::bad_alloc to be thrown, how come you're using the nothrow version of new[]?
It will return 0 on failure, the normal one throws a bad_alloc exception on failure.
OK, so if I remove std::nothrow, a bad_alloc exception is thrown if new fails? If that's the case, will the raised bad_alloc exception be thrown again by the function?