Reputation: 9366
In the book "C++ Programming language" by Bjarne Stroustrup when talking about exceptions it says the following:
An exception is object thrown to represent the occurrance of an error. It can be of any type that can be copied but it is strongly recommended to use only user-defined types specifically defined for that purpose.
Reasoning about it I cannot immediately think of objects that cannot be copied. What are types that cannot be copied in C++?
Upvotes: 0
Views: 500
Reputation: 133609
To be copyable an object must define at least one of two possible ways of being copied:
T& operator=(const T&)
T(const T&)
If no one of these is defined or it has been explicitly deleted (= delete
) then you can't copy the object.
The requirement arises from the fact that exception handling must be able to copy the exception object itself somewhere for proper management.
Upvotes: 5