On 2008-04-30 18:43, Martin T. wrote:
> Hi all,
>
> I'm currently trying to come up with a decent exception base class for
> some modules of ours and was thinking about adding exception-chaining
> (yes, like in Java :-)
> The following points where im****tant for me:
> * Must inherit from std::exception
> * Should allow for a std::exception to be the start of the exception
chain.
> * throw by value / catch by const reference
>
> As exception chaining seems to be rather obscure with C++, I'm
> interested what other think about the solution (find code below).
>
> thanks,
> br,
> Martin
>
>
>
> --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?
2. Will not e be destructed when you throw an exception leaving with a
dangling pointer in the chained_exception instance?
--
Erik Wikström
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


|