More than likely your error is due to the data input, if the input wasn't sanitized the convert method may be throwing an error since the value cannot be converted to an integer. Some fundamental knowledge appears to be missing, based on your comment.
"I'm reading a file."
public static IEnumerable<string> ReadTrackFile(FileInfo file)
{
var line = String.Empty;
using(StreamReader reader = File.OpenText(file.FullName))
while((line = reader.ReadLine()) != null)
yield return line;
}
So we've created a method to read the contents of our file. The method also captured all the individual lines. Due to the lack of clarification I'll assume you have a delimited file with the following format.
Jimmy Hendrix - Greatest Hits - 1 - Gypsy Eyes
So we would shape our object like the following.
public class Music
{
public string Artist { get; set; }
public string Album { get; set; }
public int TrackNumber { get; set; }
public string TrackName { get; set; }
}
Now that our object is defined, we would do something along these lines.
var output = ReadTrackFile(...);
foreach(var record in output)
yield return ArtistMapper.MapToObject(record);
Basically the mapping aspect you can do, but you would be mapping those values directly to your object. But that would be a more appropriate approach.
As for your validation, you can simply do the following.
int.TryParse(value, out output);
You could then use output, but it'll hold zero as a default or you can conditionally check to make sure a value is an integer before attempting to use. Code flow and application requirements would specify which approach to use.