Re: Exceptions as smart pointers
Peter Dimov wrote:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2509.html
Yes, std::nested_exception could really help.
I, personally, would have preferred the N2509 functionality to go
directly into std::exception, but this would have raised ABI
compatibility issues.
But my code works right now. It was published in 2004, to be exact.
Also there is some problem with certain compilers (can be checked with
mtprog\derslib\tst\tst_exc.cpp). The point is that a correct compiler
needs only one catch(...) block:
void f(mem_pool& mp, /* ... */)
{
try {
g(mp, i);
// ...
return;
}
catch (...) {
throw newException(_FLINE_, "Problems in f()",
recatchException(mp, _FLINE_));
}
}
But other compilers crash with this code and require one more catch:
void f(mem_pool& mp, /* ... */)
{
shException exc(mp, 0);
try {
g(mp, i);
// ...
return;
}
catch (shException she) { exc=she; }
catch (...) { exc=recatchException(mp, _FLINE_); }
throw newException(_FLINE_, "Problems in f()", exc);
}
P.S.
The code: http://ders.stml.net/cpp/mtprog/code.zip
The doxygen: http://ders.stml.net/cpp/mtprog/doc/index.html
--
With all respect, Sergey. http://ders.stml.net/
mailto : ders at skeptik.net
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]