see
http://www.wintellect.com/resources/newsletters/articles/appsdie.aspx"...
WinForms Applications
WinForms application exception handling has a twist in it. Exceptions for the main thread go to a different handler than exceptions from the other threads. You'll need to add a delegate to the Application.ThreadException member that has the type System.Threading.ThreadExceptionEventHandler in order to handle them. If you want notification of exceptions from other threads, you'll have to also set the AppDomain.CurrentDomain.UnhandledException event, as I discussed in the previous section.
..."

解决方案 »

  1.   

    非常感谢你关注我这个问题,可是上面的文章对我没有什么帮助,我用2003自带的SDK里的sample:ExceptionsVB,它是控制台的,它就可以,我的就不可以。    我已设了自已的错误处理(MyException),在调试时是能够执行到的(MyException),但是如果离开IDE后执行,弹出系统的异常提示窗后单击继续会忽略我的错误继续执行我的程序,后不执行自定义异常处理。当不能忽略错误出现调试窗体,关闭调试窗体后不会执行自定义异常代码。代码如下:
    Module Module1    Sub main()
          AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf MyException
          Application.Run(new myForm)
        End SubSub MyException(ByVal sender As Object, ByVal args As UnhandledExceptionEventArgs)
            MessageBox.Show("Unhandled Exception!" & ControlChars.CrLf & args.ExceptionObject.GetType().ToString(), "Exceptions")
        End Sub
    End ModulePrivate Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load     Throw (New System.Exception)
         '我也试过:
         'Throw (New System.ExecutionEngineException)
    End sub
      

  2.   

    Module Module1    Sub main()
          AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf MyException
          AddHandler Application.ThreadException, AddressOf YourThreadExceptionEventHandler
          Application.Run(new myForm)
        End SubSub MyException(ByVal sender As Object, ByVal args As UnhandledExceptionEventArgs)
            MessageBox.Show("Unhandled Exception!" & ControlChars.CrLf & args.ExceptionObject.GetType().ToString(), "Exceptions")
        End Sub
       Sub YourThreadExceptionEventHandler(ByVal sender As Object,  ByVal e As System.Threading.ThreadExceptionEventArgs)
    MessageBox.Show(e.Exception.Message)
       end Sub
    End Module
      

  3.   

    看一下Petshop3.0的错误处理机制;
    有的也写到系统日值文件里面;
      

  4.   

    上面的仁兄(NetAnt007(飞呀飞))是不是没有理解我的意思,我是想在没有Try   catch时发生异常也能够由自已在一个统一的地方处理,并不是记录在那里,否则只要有一个TextWriter(抽象)写在那儿都可以。
      

  5.   

    非常感谢思归,问题已经解决了。
    用Application.ThreadException可以,在调试和运行时的效果是一样的。而AppDomain.CurrentDomain.UnhandledException在调试时可以,在独立运行则不行。