When writing a function I always have this confusion whether to check for errors first and declare the variables later (or) assign the parameters to local variables and then check for errors. Which of the following way is preferred and why? I usually stick to the first type.
void DoSomething1(Object x, Object y){
// All sort of error checking goes here
if IsError(x) return;
if IsError(y) return;
// Variable declaration
int i,j;
Object z = x;
}
void DoSomething2(Object x, Object y){
// Variable declaration
int i,j;
Object z = x;
// All sort of error checking goes here
if IsError(z) return;
if IsError(y) return;
}