int ID = 0;
dataFile = new FileInfo (Application.dataPath + "/Data/CPUs.txt");
if ( dataFile != null && dataFile.Exists )
reader = dataFile.OpenText();
if ( reader == null )
{
Debug.Log("CPU data is not able to import!");
}
else
{
string line;
while ((line = reader.ReadLine()) != null)
{
string[] data = line.Split(',');
for (int i = 0; i < data.Length; i++)
{
print(data[i]);
}
Chip chip = new Chip (data[0], Convert.ToInt32(data[1]), Convert.ToInt32(data[2]), Convert.ToInt32(data[3]), Convert.ToInt32(data[4]), Convert.ToInt32(data[5]), Convert.ToInt32(data[6]), Convert.ToInt32(data[7]));
CPUs.Add(ID, chip);
ID++;
}
}
this is part of code for importing data from text file into the game and saving in the dictionary.
My question is how to check and write errors if any are there, like if i change int parameter with string (in txt file) so it reads wrong, so i would just skip that line and move to next or if in text are 7 parameters instead of 8 so error is array out of boundaries. how can i check such errors and tell them to debugger or player?