PRB: Choosing Quit in WFC Exception Dialog Box Shuts Down Host
Symptoms
When an ActiveX control created with Windows Foundation Classes for Java(WFC) is placed in Visual Basic and throws an exception, the default WFCexception dialog box gives you the choice to either Continue, Quit, or SeeDetails. If you click Quit, the entire process hosting the WFC controlquits.
In an application hosted by the Visual J++ Integrated DevelopmentEnvironment (IDE), this is okay because the application is running in adifferent process than the IDE. However, in Visual Basic, the IDE and theapplication are in the same process until you actually make an .exe, sochoosing Quit kills the entire Visual Basic IDE, along with any unsavedwork.
Resolution
There are two methods for resolving this issue. The first method is tonever choose Quit in the WFC exception dialog box that appears when youreceive an unhandled exception while hosting a WFC control in a VisualBasic application while running in the Visual Basic IDE. Instead, youshould always choose Continue and then shut down the Visual Basicapplication from within the Visual Basic IDE.
The second method is to add an onThreadExceptionEventHandler to your WFCActiveX control. This event handler is called instead of the default WFCexception handling routines and the default dialog box that contains theQuit option does not appear. Your WFC control, however, is responsible forhandling exceptions, notifying the user, and shutting down as necessary.
Sample CodeThe following sample code adds a very simple ThreadException Handler to aWFC 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 SteveHorne, Microsoft Corporation.
