There is a try-catch thing about functions, which I think sometimes may be quite useful:
bool function()
try
{
//do something
}
catch(exception_type & t)
{
//do something
}
So the first part of the question: is this style considered bad in general case?
And the concrete example I used this approach in:
We had project with quite a lot of code in c and c++. And there we had custom exception types (not std::exception derived). I needed to integrate XML library and cast all exception to our types. So, basically, the last step was to catch all exceptions from XML library and convert them.
Function before:
bool readEntity(...)
{
while(...)
{
if(...)
{
//lot's of code...
}
}
}
after:
bool readEntity(...)
try
{
while(...)
{
if(...)
{
//lot's of code...
}
}
}
catch(XMLBaseException & ex)
{
//create our exception and throw
}
My thoughts went something like this: I clearly state my intentions to convert all exception derived from one type into custom type AND we keep our screen without horizontal scroll bar (cause horizontal scroll bars are bad).
Well, I actually was quite criticized for this approach as for non-clear one during code review.
So I'd like to hear you thoughts.
UPDATE: just to be clear: refactoring the function wasn't an option. And actually it was good written one.