要求:   上的错误(抛出的异常),正在处理的文件应该被移动到文件夹的文件有错误(app.config中设定)。

的问题:   我可以处理这个是有主的try / catch内嵌套的try / catch尝试移动文件的唯一方法,如果此举失败,这样一来,抛出了另一个错误。我知道我可以尽我所能,以确保该目录存在,权利,乃因为它是一个网络驱动器...我只知道一个错误,势必在某一时刻发生的。

实施例

Try
   (Do Some Logic, but an error happens)
Catch ex As Exception
   Try
       (Attempt to move file)
   Catch exinner as Exception
       Throw New Exception("Cannot move file to Error Directory", innerex)
   End Try
   (Raise Error Event for logging by form/batch app)
End Try

其实说出来甚至比我在想什么它看起来就像更加可怕。

现在我知道我做错了什么。应该如何我真的试图以处理可能出现的错误在catch存在的,所以我仍然可以移动文件,并试图打电话给我的事件?

有帮助吗?

解决方案

这一切对我来说很好。这是完全合理的,有抓内尝试catch块。您可以检查所有你所提到的事情,但总是有网络会下降,或者你只是简单的将不能够编写文件的可能性。之后你要做的就是给你。错误信息,并暂停加工似乎是合理的。

其他提示

这是完全只能用异常时,你会怎么做。您可以考虑使用的标志,但是这不是好不了:

(Set file processing error flag to false)
Try
   (Do Some Logic, but an error happens)
Catch ex As Exception
   (Set file processing error flag to true)
End Try

IF (file processing error flag = true)
   Try
       (Attempt to move file)
   Catch exinner as Exception
       Throw New Exception("Cannot move file to Error Directory", innerex)
   End Try
   (Raise Error Event for logging by form/batch app)
End Try

这并不是说要好得多......

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top