Simple answer: Don't declare it noexcept, if you know it may throw and you do not have a really good reason to do so (for instance you want your application to call std::terminate if a copy cannot be made).
Ask yourself what the gain would be. Can the compiler optimize anything when it is noexcept? I do not see many cases where this would be the case (the most common case where I see optimizations is for a move as then the std-library containers can use it - they check if a move operation is noexcept so they can keep their guarantees). The other place where you might use it is when you want to document that a function cannot throw. This is obviosuly not the case here.
On the other hand, you will not be able to recover from a possible exception anymore and your program will terminate.
So in summery, you do not gain anything, but you might lose something.
Also consult the core guidelines:
E.12: Use noexcept when exiting a function because of a throw is impossible or unacceptable
The title of this rule may be a little bit confusing. It says that you should declare a function as noexcept, if
- it does not throw or
- you don't care in case of an exception. You are willing to crash the program because you can not handle an exception such as std::bad_alloc due to memory exhaustion.
It's not a good idea to throw an exception if you are the direct owner of an object.
By the way, the following special member functions are implicitly noexcept:
- Default constructor
- Destructor (as far as I know even if you explicitly throw in it)
- Move and copy constructor
- Move and copy assignment operator
In practice, implicit destructors are noexcept unless the class is "poisoned" by a base or member whose destructor is noexcept(false)
– Vinni