jeudi 10 mai 2018

How to return from method where an error is encountered but type is expected

Assume I have a method that returns a List<int> and that in the process of getting this List<int> an error occurs such that the data cannot be gathered. What is the best way to handle this exception within the method? The program is expecting the method to return a List but since, for whatever reason , an error occurred it can no longer do this. What should I return from the method? Is it a custom exception that is caught by the calling code?

private List<int> GetData()
{
  List<in> theData = new List<int>();
  theData = ProcessThatGetsData(); //Error occurs in here
  return theData;  //What should be returned here?
}

Aucun commentaire:

Enregistrer un commentaire