If you have a public function which may throw an exception which uses other (private or public) helper functions which can also throw exceptions I think you should document what exceptions the public function can throw and this includes exceptions thrown by the helper functions.
Something like this (using Doxygen):
/**
* @throw Exception ...
* @throw ExceptionThrownByHelper ...
* @throw ExceptionThrownByHelpersHelper ...
*/
void theFunction()
{
helperWhichMayThrowException();
}
and helperWhichMayThrowException()
also calls other functions which may throw exceptions.
To do this you can:
- recursively follow all functions
theFunction()
calls and look for exceptions thown by that function. This is a lot of work and you might forget to document an exception somewhere when you add an exception to a helper. - catch all exceptions thrown by helpers in
theFunction()
and convert them so you are sure only the exceptions you specify are thrown. But then why use exceptions? - do not worry about exceptions thrown by helper functions but then you can not unittest all exceptions because you do not know which exceptions can be thrown by the public function
- have some tool which (semi)automatically lists all exceptions thrown by helpers etc. I looked in the documentation of Doxygen but did not find a way to do this.
I would like to use option 4 but I have not found a good solution yet, maybe it is doable with Doxygen? Or maybe I just want to document to much???
edit: Maybe its not really clear but I am looking for an easy way to document all exceptions (preferably using Doxygen) a function might throw without manually checking all helper functions. An easy way includes 'do not document all exceptions' or 'catch and transform all exceptions in theFunction()
'