发布模式下的异常处理问题 [英] Exception handling problem in release mode
问题描述
模块启动
< STAThread()> _
Public Sub Main()
尝试
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
InitApp()
Dim login As New LoginForm()
Dim main As New MainForm()
Application.Run(login)
如果login.DialogResult = DialogResult。 OK然后
ActUser = login.LoggedUser
main.ShowDialog()
如果
DisposeApp()
捕获ex As Exception
ErrMsg(例如Error!,ErrorLogger.ErrMsgType.CriticalError)
结束
结束尝试
结束子
结束模块
在调试模式下,everithing可以。
但是在发布模式下,当应用程序异常发生时,我在Main方法中的全局捕获不会捕获异常。
请问有什么问题? >
编辑:应用程序的未处理异常是Web服务调用失败后引发的WebException。
我如何处理这种类型的异常?
这是正常现象。 Application.Run()方法中有一个异常处理程序。为了使调试异常变得更容易,您调试时禁用 。没有调试器,异常处理程序将显示ThreadExceptionDialog。
将此语句添加到Main方法的顶部以禁用此异常处理程序:
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException)
I have application with this code:
Module Startup
<STAThread()> _
Public Sub Main()
Try
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
InitApp()
Dim login As New LoginForm()
Dim main As New MainForm()
Application.Run(login)
If login.DialogResult = DialogResult.OK Then
ActUser = login.LoggedUser
main.ShowDialog()
End If
DisposeApp()
Catch ex As Exception
ErrMsg(ex, "Error!", ErrorLogger.ErrMsgType.CriticalError)
End
End Try
End Sub
End Module
in debug mode everithing is OK. But in release mode when somewhere in application exception occurs my global catch in Main method doesn`t catch exception.
What is the problem please?
EDIT: unhandled exception from application is WebException thrown after failed web service call.
How can I handle this types of exceptions?
This is normal. There's an exception handler built into the Application.Run() method. It is disabled when you debug in order to make debugging exceptions easier. Without a debugger, the exception handler will display the ThreadExceptionDialog.
Add this statement at the top of your Main method to disable this exception handler:
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException)
这篇关于发布模式下的异常处理问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!