I have the following code:
In Game.h:
mtm::Dimensions dimensions;
std::vector<std::shared_ptr<Character>> board;
In Game.cpp:
Game::Game(int height, int width) : dimensions(height, width), board(height * width, nullptr)
{
if (height <= 0 || width <= 0) {
throw mtm::IllegalArgument();
}
}
But as you may notice I'm throwing the error too late, if height * width is smaller than 0 then a bad_alloc will be thrown instead of IllegalArgument, How may I fix this?
Is there a way to throw an exception in the initialisation list?