Which one is better to use?
if (condition)
{
flagCheck = true;
//Service layer call - code.
flagCheck = false;
}
OR
if (condition)
{
flagCheck = true;
try
{
//Service layer call - code.
}
finally
{
flagCheck = false;
}
}
What is the difference between the two methods? Are there situations where one can be used preferably more than other?
In the first case,
flagCheckremainstrueif// Service layer call - codethrows an exception, while in the second caseflagCheckwill be set tofalseafter// Service layer call - coderegardless of whether an exception is thrown or not.Neither of the two cases is inherently better than the other; pick the one that does what you need.