This really isn’t an important question. I just wanted to know which method is more popular and whether there’s some sort of a de facto standard.
This,
function foobar
{
int retVal = 0;
try
{
retVal+=100;
}
catch
{
//error handling code
}
return retVal;
}
Or this?
function foobar
{
try
{
return 100;
}
catch
{
//error handling code
}
return 0;
}
It really depends upon what the function is doing. Use of a
retValvariable is useful when then function need to go though a few operations to construct the return value. If the return value is more atomic than that I wouldn’t bother with the extra variable.