C# Visual Basic 2013中的异常错误

C# Visual Basic 2013中的异常错误,c#,csv,exception,C#,Csv,Exception,我尝试使用C从运行代码,但它在运行时出现错误并给出以下消息 发生类型为“System.exception”的未处理异常 我已尝试修复错误,但将出现另一个错误。有人能帮我找到代码中出现的问题吗 public Pattern(string value, int inputSize) { string[] line = value.Split(','); if (line.Length - 1 != inputSize) throw new Exception("Inp

我尝试使用C从运行代码,但它在运行时出现错误并给出以下消息

发生类型为“System.exception”的未处理异常

我已尝试修复错误,但将出现另一个错误。有人能帮我找到代码中出现的问题吗

public Pattern(string value, int inputSize)
{
    string[] line = value.Split(',');
    if (line.Length - 1 != inputSize)
        throw new Exception("Input does not match network configuration"); //error occur
    _inputs = new double[inputSize];
    for (int i = 0; i < inputSize; i++)
    {
        _inputs[i] = double.Parse(line[i]);
    }
    _output = double.Parse(line[inputSize]);
}
我看到的唯一抛出System.Exception的方法是:

if (line.Length - 1 != inputSize)
    throw new Exception("Input does not match network configuration"); //error occur
这可能意味着您在CSV int inputSize中所说的列数与通过逗号字符拆分在值中实际找到的列数不匹配

string[] line = value.Split(',');
检查CSV文件,确保其列数与您指定的列数相同


还要注意的是,如果数据本身中的逗号处理不当,可能会导致此错误。例如,如果您有一个包含FirstName和LastName列的CSV,添加John,Smith,Jr将使它看起来像是有一个额外的列。

就此而言,对double.Parse的调用可能会抛出,新的也可能抛出,尽管我希望在这种情况下会看到不同的异常类型。@codingthewheel:那将是System.FormatException,不是System.Exception。正如我所说,在这种情况下,我希望看到不同的异常类型: