Re: Looking for an elegant way to convert API methods throwing
exceptions to new API methods returning codes
On 2011-11-04 09:35, Andrzej Krzemie??ski wrote:
I also thought this way at first, but in Castor's example error code
is a mandatory output argument for each function. You cannot
inadvertently ignore it, because then the compiler will protest about
the missing argument. You can obviously cheat by passing a dummy
argument, but this is an "explicit ignore", similar to catch(...){}
Experience shows that this is wishful thinking ;-) It doesn't much
matter whether you need to provide an argument to the function. You can
(and the resistant once will for sure) simply ignore what the function
has written to it.
In fact a coworker of mine had suggested a while ago the following to
make error-code based more robust against other resistant coworkers that
tend to ignore to check these error values: Just invent a class type
that behaves like an error code value, but recognices whether its value
has been read or not. In the destructor of this wrapper check for
reading and either terminate or throw an exception (as ugly as this
might be), to prevent that user ignores reading the value.
As you see, this was just the opposite suggestion as what the OP meant,
but I'm sure that even such a class would not prevent sufficiently
resistant people to still ignore the value ;-)
Greetings from Bremen,
Daniel Kr??gler
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]