When I execute the following function, I get an error:
“Error ‘Excel1.WebServiceFunctions.CreateMyTask()’:
not all code paths return a value
My Code:
public int CreateMyTask()
{
try
{
Console.WriteLine("Invoking CreateTask method");
Console.WriteLine("-----------------------------------");
m_taskID = taskClient.CreateTask(m_tInstance);
Console.WriteLine("Task create successfully:ID=" + m_taskID.ToString());
Console.WriteLine("-----------------------------------");
return m_taskID;
}
catch (Exception ex)
{
MessageBox.Show("An exception has occured. Please check the Excel sheet for more info" + ex);
}
finally
{
GC.Collect();
}
}
Any idea on how I can go behind this? I did a bit of googling but I am not able to zero in exactly
Reason
Consider this scenario.
An error occurs in code line before return line in try block. Then it will go in catch show messagebox and then in finally and then return what????? It has to return something cause method return type is int.
Solution
Do this