0 Replies Latest reply: Oct 18, 2012 3:02 AM by 969173 RSS

    Application UnhandledException not caught when using OracleConnection

    969173
      Hello,
      i have a Windows Forms .Net 2.0 App which defines AppDomain.CurrentDomain.UnhandledException handler.
      When an app thread throws an exception this exception is caught or handled by this method.

      The problem is that if i define an OracleConnection, open and close it and then the thread throws the exception this is not handled and app finishes...

      Why i can't handled this threads exceptions if i use OracleConnection?

      Here is the simple app code example:

      program.cs

      [STAThread]
      static void Main()
      {
      AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
      Application.ThreadException += Application_ThreadException;
      Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException);
      Application.EnableVisualStyles();
      Application.SetCompatibleTextRenderingDefault(false);
      Application.Run(new Form1());
      }
      public static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
      {
      MessageBox.Show("Thread exception");
      }
      public static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
      {
      MessageBox.Show("Domain exception.");
      }

      Form1.cs

      public Form1()
      {
      InitializeComponent();

      OracleConnection conn = new OracleConnection();
      conn.ConnectionString = "User ID=mlxtrunk;Password=mlx;Connection Lifetime=1;Data Source=INTERFACE01/ORCL;Pooling=false";
      conn.Open();
      conn.Close();
      conn.Dispose();
      }
      private void btn_Ok_Click(object sender, EventArgs e)
      {
      Thread t = new Thread(new ThreadStart(ExceptionThread));
      t.Start();
      t.Join();
      }
      public void ExceptionThread()
      {
      System.Threading.Thread.Sleep(1000);
      throw new InvalidOperationException("nooo");
      }