如何关闭程序的错误提示,以统一的画面提示?
程序开发以后,在用户运行的过程中,会有可能发生各种各样的错误,请问如何屏蔽这些错误,而用一个统一的一个错误提示来告诉用户?因为系统的错误提示,有可能会暴露你程序中的一些关键字。
简单的讲,我如何控制程序中的所有错误的基类?
[解决办法]
参考AppDomain.UnhandledException
Sub Main()
Dim currentDomain As AppDomain = AppDomain.CurrentDomain
AddHandler currentDomain.UnhandledException, AddressOf MyHandler
Try
Throw New Exception( "1 ")
Catch e As Exception
Console.WriteLine( "Catch clause caught : " + e.Message)
End Try
Throw New Exception( "2 ")
' Output:
' Catch clause caught : 1
' MyHandler caught : 2
End Sub 'Main
Sub MyHandler(sender As Object, args As UnhandledExceptionEventArgs)
Dim e As Exception = DirectCast(args.ExceptionObject, Exception)
Console.WriteLine( "MyHandler caught : " + e.Message)
End Sub 'MyUnhandledExceptionEventHandler