Here's a bit of lateral thinking: whenever you think you need throws or pointers, think again. If you need only 100 unsigned bytes of memory, use
std::array<unsigned char, 100> data;
or
unsigned char data[100];
If the size is not constant, use a vector:
std::vector<unsigned char> data(size);
Raw pointers, the new
operator, and throws are unsafe, hard to access, and make your program difficult to understand. Avoid them if possible.
source share