代码之家  ›  专栏  ›  技术社区  ›  Henric

保存文件集合并继续出错

  •  0
  • Henric  · 技术社区  · 16 年前

    当发生不好的事情时,如何保存几个文件并记录错误,然后继续按顺序处理下一个文件?基本上,我将有一个pdf文件的集合,我想保存在一个特定的位置。如果在处理文件时抛出错误,则应记录该错误,然后继续保存序列中的下一个文件?这还在计划阶段,所以我没有任何代码可以共享。我只是想了解一下什么样的解决方案是合适的,并找出任何陷阱。

    1 回复  |  直到 16 年前
        1
  •  4
  •   Alexander    16 年前

    你可以这样做。

    foreach (var file in files)
    {
        try
        {
            // Save the file
        }
        catch (Exception e)
        {
            // Log exception
            Console.WriteLine(e.Message);
            // Do not re-throw the exception
        }
        continue;
    }