Looking for an elegant way to convert API methods throwing
exceptions to new API methods returning codes
Hi all,
I am using an API exporting many classes and each class export many
methods.
Each method is throwing some "APIException" exception instance when
something goes wrong.
We are not very happy with this because our developpers use to
forgetting catching the exceptions so many applications crash because
of this.
I can not modify the API (this a third-party API) so my code must not
be intrusive.
I would like to find an elegant way to surround each API method call
with a try/catch then return the exception code as the error code like
this:
void mynewclass::mynewmethod(... /* API method arguments */, int &err)
{
try
{
class.method(... /* API method arguments */);
}
catch(APIException e)
{
err = e.getErr();
}
}
class::method() is the API implementation and
mynewclass::mynewmethod() would be the new API surrounding
implementation.
In order to implement this, I was thinking of using a C++ template but
I can not imagine writing a template for each of the hundred of
different method's names defined in the API.
Consequently, I am looking for a simple and short code converting the
exception throwing mechanism by the (plain old) error code returning
mechanism.
Thanks in advance if you have any idea.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]