【发布时间】:2013-11-08 17:37:43
【问题描述】:
我有一个非常密集的函数,在一系列数据上运行一个循环。
它很少使用,但我需要能够捕获任何 TimeOut 错误并安排重新启动。
有什么办法吗?
或者我只需将ScriptTimeout 设置为一些愚蠢的东西?
【问题讨论】:
-
能贴出相关代码吗?又是怎么称呼的?
我有一个非常密集的函数,在一系列数据上运行一个循环。
它很少使用,但我需要能够捕获任何 TimeOut 错误并安排重新启动。
有什么办法吗?
或者我只需将ScriptTimeout 设置为一些愚蠢的东西?
【问题讨论】:
不知道您在做什么或您的代码是什么样的,但这里有一个示例,在捕获错误时最多运行 10 次。您应该只针对某些错误执行此操作,例如超时错误,而不是所有错误,如此处所示。
Dim bSuccess as boolean = false
Dim iLoop as byte = 0
do while not bSuccess
iLoop += 1
Try
..Your code/method here
bSuccess = true
Catch ex as Exception
'Check for max number of retries
If iloop >= 10 then
..What do you want to do, bSuccess = true, Exit Do, Exit Sub, Throw ex, etc
End if
'Check if certain type of error to get out of loop
End Try
loop
【讨论】: