I thought exceptions imposed a bit more on the thrown type than the standard actually imposes. I want to clear up this confusion. What is actually imposed on those types?
Asked
Active
Viewed 69 times
1 Answers
4
The C++ ISO spec, §15.1/3, states that
The type of the throw-expression shall not be an incomplete type, or a pointer or reference to an incomplete type, other than void*, const void*, volatile void*, or const volatile void*. Except for these restrictions and the restrictions on type matching mentioned in 15.3, the operand of throw is treated exactly as a function argument in a call (5.2.2) or the operand of a return statement.
From this, it seems that you should be able to throw anything you'd like, as long as you're not throwing a type that you've only forward-declared.
EDIT: As @Billy ONeal points out, the type must be copyable, which means that it should support a copy constructor.

templatetypedef
- 362,284
- 104
- 897
- 1,065
-
1I think it needs a copy constructor anyway, given 15.1 paragraph 3 `A throw-expression initializes a temporary object, called the exception object` – Billy ONeal Jul 28 '11 at 19:44
-
@Billy ONeal- Thanks for pointing that out! I'll update my answer. – templatetypedef Jul 28 '11 at 19:46