如题,
如题,
如题,
如题,
如题,
如题,
如题
本来记得应该类似WPF,WinForm也有一个事件用以处理未捕获的异常,不过搜了一下发现不太一样,参考 http://developer.51cto.com/art/200912/173003.htm
除了上文的方式,你还可以在 Main 中,把 Application.Run(new Form1()); try catch 住,如下:
try{Application.Run(new Form1()); }catch(exception e){}
可以的。我用以下语句,可能不全,你可以再GOOGLE下。
Public Shared Sub ApplyExceptionHandle()
Try
AddHandler AppDomain.CurrentDomain.UnhandledException, New UnhandledExceptionEventHandler(AddressOf CurrentDomain_UnhandledException)
AddHandler Application.ThreadException, New System.Threading.ThreadExceptionEventHandler(AddressOf Application_ThreadException)
Catch ex As Exception
AppMessagebox.Show(ex.Message & System.Environment.NewLine & My.Resources.LocalizeRes.FunctionErrorOccur & MethodBase.GetCurrentMethod.Name)
End Try
End Sub
Shared Sub Application_ThreadException(ByVal sender As Object, ByVal e As System.Threading.ThreadExceptionEventArgs)
AppMessagebox.Show(e.Exception.ToString(), "系统错误", Windows.Forms.MessageBoxButtons.OK, Windows.Forms.MessageBoxIcon.Error)
End Sub
Shared Sub CurrentDomain_UnhandledException(ByVal sender As Object, ByVal e As UnhandledExceptionEventArgs)
AppMessagebox.Show(e.ExceptionObject.ToString(), "系统错误", Windows.Forms.MessageBoxButtons.OK, Windows.Forms.MessageBoxIcon.Error)
End Sub
try catch应该可以的啊