Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
839 views
in Technique[技术] by (71.8m points)

vb.net - Exception handling problem in release mode

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...