
This can be done by adding a clone() virtual function to boost::exception.
Since the clone function is just a stopgap until 0x, would it be better to implement it without explicitly adding the clone function to the interface? For example, use an auto-registration idiom to collect all of the exception types: void throw_exception(const E&e) { static autoregister_exception<E> registration; throw e; } Provide an implementation of "copy_exception" that searches for a type_info match. Perhaps this clumsy implementation is better than everyone ending up a few years from now with dependencies on an obsolete clone interface.
Why not throw a std::ostringstream directly then? :)
I was just trying to demonstrate that: - Tagged fields could be mixed with untagged fields to encourage more ad-hoc data in the exception (to aid debugging). - Both untagged and tagged types can be visited by the error handler in a type-safe manner. Tagging is only really required when the identity of the field would otherwise be ambiguous. - Fields from one exception object could be copied into a second. - Formatting of the "what" message can be specified inline at the throw site but remain uninterpreted until the error handler is reached. -Joshua Napoli