I use QT 4.8 (C ++) for a desktop application project and write exception handling that looks like this:
void callerMethod()
{
try
{
method1();
}
catch(Exception1& e)
{
}
catch(std::Exception& e)
{
}
catch(...)
{
}
}
void method1()
{
try
{
}
catch(Exception1& e)
{
throw e;
}
catch(Exception2& e)
{
throw e;
}
catch(Exception3& e)
{
throw e;
}
catch(...)
{
throw;
}
}
So my question is: do I need to write cleanup code in every catch block ? Is there a way I can avoid writing duplicate code ?
NOTE :: [ In method1 () ] I want to repeat the exceptions that occurred to my caller.So I cannot catch them in one catch block, because then the type information will be lost.
source
share