|
Boost Users : |
Subject: [Boost-users] [exception] Conditional error_info addition
From: Adam Badura (abadura_at_[hidden])
Date: 2010-02-16 02:22:00
Is there a way to add error_info to an exception object conditionally?
In my use case I throw upon error during Windows Registry manipulation.
One of the data attached to the exception object is the path to the registry
key on which operation failed. The problem however is that sometimes (while
the library is still developed...) the failure is due to internal code
error: the handle to the key is no longer valid because it was closed
(erroneously) previously.
In such case obtaining path to the key will yield an empty string. I
don't want to attach an empty string. I would prefer not to attach anything.
(Now actually in this particular case it might be even useful to attach
an empty string which is then a clear indication that the key handle was
invalid. However I hope that my point is clear here.)
Currently I would have to do something like:
ExceptionType e;
std::wstring path = getPath( hKey );
if ( !path.empty() )
e << PathInfo( path );
BOOST_THROW_EXCEPTION( e );
This code however involves more copying with little hopes for optimization.
And it is obviously long. If this was to be done for two or three data items
the throwing code would become quite long...
Can anything be done about it? Can we have some form of conditional
error_info insertion?
Adam Badura
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net