you don't have to return a new instance, but you have to return something in all cases. The way you had it set up, if it threw an exception, you caught the exception and put up an error but never returned anything.
Another way you could handle it would be to get rid of the return from within the try block. In the catch block, set command to something. And put the return statement in the finally block. Which is probably how I would handle it.
Maybe something like
catch (Exception ex)
{
Console.Write ("Error in connection : "+ex.Message);
command = new SqlCommand();
command.CommandText = "Error";
}
finally{
return command;
}
Then, when you call the function you can do something like:
SqlCommand newCommand = fncreateCmdObj(name, Parameters, transaction);
if (newCommand.CommandText !="Error")
{
//do whatever
}
Hope this makes sense