If I have a method that returns something, like
public DataTable ReturnSomething() { try { //logic here return ds.Tables[0]; } catch (Exception e) { ErrorString=e.Message; } }
This produces compiler error, obviously because catch{} block does not return anything.
So when I have methods with return values I don’t use try-catch block, which is a bad practice. If there is an error, I would like to set error string to that error. But then I need a return value as well. Advice?
Store your return value in a temporary variable like this: