1

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?

Community
  • 1
  • 1
Billy ONeal
  • 104,103
  • 58
  • 317
  • 552

1 Answers1

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