PRB: Choosing Quit in WFC Exception Dialog Box Shuts Down Host

ID: Q197032


The information in this article applies to:
  • Microsoft Visual J++, version 6.0
  • Microsoft Visual Basic Standard, Professional, and Enterprise Editions for Windows, version 4.0


SYMPTOMS

When an ActiveX control created with Windows Foundation Classes for Java (WFC) is placed in Visual Basic and throws an exception, the default WFC exception dialog box gives you the choice to either Continue, Quit, or See Details. If you click Quit, the entire process hosting the WFC control quits.

In an application hosted by the Visual J++ Integrated Development Environment (IDE), this is okay because the application is running in a different process than the IDE. However, in Visual Basic, the IDE and the application are in the same process until you actually make an .exe, so choosing Quit kills the entire Visual Basic IDE, along with any unsaved work.


RESOLUTION

There are two methods for resolving this issue. The first method is to never choose Quit in the WFC exception dialog box that appears when you receive an unhandled exception while hosting a WFC control in a Visual Basic application while running in the Visual Basic IDE. Instead, you should always choose Continue and then shut down the Visual Basic application from within the Visual Basic IDE.

The second method is to add an onThreadExceptionEventHandler to your WFC ActiveX control. This event handler is called instead of the default WFC exception handling routines and the default dialog box that contains the Quit option does not appear. Your WFC control, however, is responsible for handling exceptions, notifying the user, and shutting down as necessary.

Sample Code

The following sample code adds a very simple ThreadException Handler to a WFC ActiveX control:

   // ... Other WFC imports ...
   import com.ms.wfc.app.*; // This creates the Application object.

   public class Control1 extends UserControl {

      // Define a Thread Exception Handler Delegate.
      private void threadException(Object sender, ThreadExceptionEvent e) {
         MessageBox.show("In Exception Handler");
      }

      public Control1() {
         // Add the Thread Exception Handler delegate.
         Application.addOnThreadException( new ThreadExceptionEventHandler
         (this.threadException));

         // Required for Visual J++ Form Designer support.
         initForm();
      }

   // The rest of your WFC ActiveX control goes here... 
(c) Microsoft Corporation 1998, All Rights Reserved. Contributions by Steve Horne, Microsoft Corporation.


STATUS

This behavior is by design.

Additional query words:

Keywords : kbVBp400 kbVJ600bug kbwfchtml
Version : WINDOWS:4.0,6.0
Platform : WINDOWS
Issue type : kbprb


Last Reviewed: August 27, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.