如果我调用csv.Read()
一个完全为空的 CSV 文件,则会出现异常。有没有办法检查 CSV 而不必依赖 Catch 块?
var csv = new CsvReader(csvFile);
try
{
while (csv.Read())
{
// process the CSV file...
}
}
catch (CsvReaderException)
{
// Handles this error (when attempting to call "csv.Read()" on a completely empty CSV):
// An unhandled exception of type 'CsvHelper.CsvReaderException' occurred in CsvHelper.dll
// Additional information: No header record was found.
MessageBox.Show(MessageBoxErrorMessageExpectedColumns, MessageBoxErrorMessageCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
return null;
}