Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: A chained e...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 7 of 8 Topic 9566 of 9828
Post > Topic >>

Re: A chained exception (base) class for C++

by Martin T <0xCDCDCDCD@[EMAIL PROTECTED] > May 2, 2008 at 12:48 PM

Eugene Gershnik wrote:
> On Apr 30, 9:43 am, "Martin T." <0xCDCDC...@[EMAIL PROTECTED]
> 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
> 
> I have been using a similar solution with similar goals for quite some
> time now and so far pretty happy about.

It's good to hear that others are using something like it. Have been
wondering why I haven't found more information about this ...

> The problem with your implementation IMO is that you burden every
> class derived from chained_exception with often unused members that
> contain information about std::exception based 'cause'. What I did to
> avoid this was to have a dedicated type, let's call it,
> std_exception_wrapper that did the job of extracting type_info, what()
> from std::exception and exposed the same chained_exception interface
> with clone() etc. The chained_exception itself ends up holding a
> single pointer to possible cause.
> 
> The usage would be
> 
> catch(std::exception & e)
> {
>      throw chained_exception(...., std_exception_wrapper(e));
> }
> 

As I would like for adding more "debugging" information to the exception
base class (file, line, function, info about current callstack) the
exception-wrapper or an exception-info class will probably come in
handy, yes.

> Another thing I've done differently is to have a generic 'printer'
> facility that allows me to do
> 
> std::cout << exception_printer(ex, <some params that might make
> sense>);
> 
> This is more flexible than having a 'print' member.
> 
Sound very neat. I find that to much genericity tends to annoy my
co-workers for some reason, so I might stick with a few focused
functions/methods :-)

> If you don't strive for universal ****tability and only intend to
> sup****t major modern platforms you also might want to store backtrace
> information in the chained_exception. Makes debugging remote
> installation problems even easier. ;-)
> 

Well, on this side we're a Windows only shop so at least I do not have
to care too much about ****tability.

Thanks for sharing your experience!
cheers,
Martin

-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 8 Posts in Topic:
A chained exception (base) class for C++
"Martin T." <  2008-04-30 10:43:22 
Re: A chained exception (base) class for C++
=?UTF-8?B?RXJpayBXaWtzdHL  2008-04-30 17:05:07 
Re: A chained exception (base) class for C++
Greg Herlihy <greghe@[  2008-04-30 22:19:30 
Re: A chained exception (base) class for C++
Martin T <0xCDCDCDCD@[  2008-05-01 13:14:31 
Re: A chained exception (base) class for C++
Eugene Gershnik <gersh  2008-05-02 04:43:58 
Re: A chained exception (base) class for C++
nickf3 <nickf3@[EMAIL   2008-05-02 04:44:00 
Re: A chained exception (base) class for C++
Martin T <0xCDCDCDCD@[  2008-05-02 12:48:14 
Re: A chained exception (base) class for C++
Martin T <0xCDCDCDCD@[  2008-05-02 12:47:51 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 15:49:35 CDT 2008.