My method returns at many points. In many cases, I create newData at runtime. No matter where I return, I need to save and keep the result built. In order not to miss the “return”, I just surrounded the code with a try-finally block, so now I’m sure that newData will be saved.
List<X> newData = new List<X>();
try
{
....
update newData
.....
return;
.....
....
update newData
....
update newData
return;
.....
return;
} finally
{
}
But I do not understand any exceptions, and this code is not intended to work with exceptions. Is this acceptable overall or can you suggest another better approach?
source
share