A
a_agaga
Hi!
Do you know different alternatives to convert exceptions in many
methods of some wrapper classes.
User -> Wrapper classes -> LibraryClasses -> ...
Wrapper classes catch an exception of only one type, let's call it
e.g. "InternalException_c".
There are no other types of exceptions, which should be catched /
converted.
The caught exception object should be converted e.g. to type
"ConvertedException_c".
Quite many methods of the wrapper classes should make the same
conversion.
void Wrapper::method1 ()
{
try {
...
} catch (InternalException_c& ex)
{
throw ConvertedException_c(ex);
}
}
The same applies to quite many methods, method1, method2, method3 ...,
maybe tens of different kinds of methods and in different wrapper
classes.
Quite many of those methods are planned to be inline, it is quite
mandatory, because those are called very intensively. Inline methods
are defined in the header:
class Wrapper2_c
....
inline void method2 ()
{
try {
...
} catch (InternalException_c& ex)
{
throw ConvertedException_c(ex);
}
}
....
What are the alternatives to avoid copy pasting the same try catch
clauses to many methods?
Macros might be one "alternative", but I think it should not be
thought as a real alternative in the C++ world.
I have thought to use some typedefs (caller should catch the typedef
instead of the real object),
but I think the best solution would be to convert the exception in the
methods of the wrapper classes. The caller should not make the
conversion. The only place, where the conversion should be made, are
the wrapper classes.
I have used templates, so if there could be a solution by using
templates (is there?) or by using some other techiques, please share
your information!
Thank you for your answers already in advance!
Do you know different alternatives to convert exceptions in many
methods of some wrapper classes.
User -> Wrapper classes -> LibraryClasses -> ...
Wrapper classes catch an exception of only one type, let's call it
e.g. "InternalException_c".
There are no other types of exceptions, which should be catched /
converted.
The caught exception object should be converted e.g. to type
"ConvertedException_c".
Quite many methods of the wrapper classes should make the same
conversion.
void Wrapper::method1 ()
{
try {
...
} catch (InternalException_c& ex)
{
throw ConvertedException_c(ex);
}
}
The same applies to quite many methods, method1, method2, method3 ...,
maybe tens of different kinds of methods and in different wrapper
classes.
Quite many of those methods are planned to be inline, it is quite
mandatory, because those are called very intensively. Inline methods
are defined in the header:
class Wrapper2_c
....
inline void method2 ()
{
try {
...
} catch (InternalException_c& ex)
{
throw ConvertedException_c(ex);
}
}
....
What are the alternatives to avoid copy pasting the same try catch
clauses to many methods?
Macros might be one "alternative", but I think it should not be
thought as a real alternative in the C++ world.
I have thought to use some typedefs (caller should catch the typedef
instead of the real object),
but I think the best solution would be to convert the exception in the
methods of the wrapper classes. The caller should not make the
conversion. The only place, where the conversion should be made, are
the wrapper classes.
I have used templates, so if there could be a solution by using
templates (is there?) or by using some other techiques, please share
your information!
Thank you for your answers already in advance!