Greg Herlihy wrote:
> On Apr 30, 4:05 pm, Erik Wikström <Erik-wikst...@[EMAIL PROTECTED]
> wrote:
>> On 2008-04-30 18:43, Martin T. wrote:
>>> --CODE--
>>> [**** Usage would then roughly be like this ***]
>>> using namespace std;
>>> using namespace my_project_ns;
>>> void f3e() {
>>> throw std::runtime_error("Any std::exception will do ...");
>>> }
>>> void f2e() {
>>> try {
>>> f3e();
>>> }
>>> catch(std_exc_catch_t e) {
>>> throw chained_exception("My exc", &e);
>> 1. Did you not want to catch by const reference?
>
> The exception "e" is being caught by const reference. See the typedef
> for "std_exc_catch_t":
>
> typedef const std::exception& std_exc_catch_t;
>
>> 2. Will not e be destructed when you throw an exception leaving with a
>> dangling pointer in the chained_exception instance?
>
> No.
>
Specifically, I pass the cause object by pointer to the
chained_exception instance and make a copy (clone) of it, if it's a
chained_exception object.
This is one of the interesting points when you want to chain exceptions
in C++, you're forced to make a copy of the original object, which makes
the whole design rather awkward. (And, as I tried with the clone method,
I think it's desireable to make a polymorphic copy.)
br,
Martin
--
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


|