public override void readFromFile(FileStream infile) { try { //read a line, use extension class String str = infile.readLine(); String[] tokens = str.Split(new char[] { ',' }); if (String.Equals(tokens[0], "Ice Cream Cone", StringComparison.OrdinalIgnoreCase)) { //throws a type mismatch exception if file is bad this.NumScoops = Convert.ToInt32(tokens[1]); this.ConeFlavor = tokens[2]; } else { //rewind the input stream, use extension class infile.rewind(); throw new ConeTypeMismatchException();//trying to read non cone data } } catch (System.IO.FileNotFoundException) { throw; }//file not found catch (System.NullReferenceException) { //something is wrong with the input file, or most likely end of file infile.Close();//close the readers reader.Close(); infile = null;//deallocate memory throw;//inform calling method there are no more records } catch (FormatException) { throw; }//input is not in the right format }