I want to write a library with "no resource leak guarantee" feature. So I shall know whether each method allocates any resource or not. It may change the code. For example:
void foo()
{
methodDontAllocateAnyResources();
methodCanThrow();
}
void bar()
methodAllocateSomeResources();
try{
methodCanThrow();
}
catch(const std::exception& exp){
releaseAllocatedResources();
throw;
}
}
Both foo() and bar() functions can throw an exception. It doesn't matter because I let exceptions to propagate. But In bar(), I must catch a possible exception to avoid a resource leak.
In the example I could decide to use or not a try-catch block easily. However, you know, normally we cannot understand whether a method allocates any resource or not by its name. So, I've decided to put this information into method documentation. Doxygen doesn't have such a tag. Also, I cannot find any web resources suggest that. Do you think using a custom @resource-allocation tag is a good idea?
Thanks
Aucun commentaire:
Enregistrer un commentaire