我制作了一个应用程序,我们公司在需要时使用它来启动数据库并在用户计算机上更新它们。
我在启动数据库方面遇到了一些问题,而且数据库启动速度很慢。当发生这种情况时,我的应用程序抛出异常,因为我假设它等待某种响应。
截至目前,抛出的错误是:系统无法找到指定的文件
我正在尝试阻止此类异常日志记录(慢速应用程序),但如果在打开数据库时发生真正的错误,仍然允许记录日志。
我正在使用的当前代码:
Private Sub OpenApplication()
If File.Exists(LocalPathString) Then ' File Found. Open the File.
Try
Dim ps As New Process
ps = Process.Start(LocalPathString)
Catch ex As Exception
ex.Source += " | " & LocalPathString
RaiseEvent ShowError(ex)
Finally
RaiseEvent CancelIt() ' Thread Complete. Close the ActionForm
End Try
Else
If LocalPathString = vbNullString Then
RaiseEvent CancelIt() ' No file exits. Cancel thread.
Else
RaiseEvent ShowError(New Exception("Database Not Located: " & LocalPathString))
End If
End If
End Sub
堆栈跟踪:
System.Diagnostics.Process.StartWithShellExecuteEx(startInfo As ProcessStartInfo)
App.exe: N 00912
System.Diagnostics.Process.Start()
App.exe: N 00136
System.Diagnostics.Process.Start(startInfo As ProcessStartInfo)
App.exe: N 00049
SAMi.ActionClass.OpenApplication()
App.exe: N 00117
答案 0 :(得分:0)
也许我错过了什么,但如果你发现了特定的例外,为什么不简单地省略日志?
Catch ex As Exception
ex.Source += " | " & LocalPathString
if not ex.Message.Contains("The system cannot find the file specified") Then
RaiseEvent ShowError(ex)
end if