One day not so long ago I was trying to make changes to my solution configuration parameters selected in VS2005 IDE and something caught my eye with reguard to the processing of unhandled exceptions. I already have an exception handler of last resort that catches all exceptions that occur in my application that I don't catch myself with a Try/Catch block provided to me by Idle_Mind. It has been serving me very well for more that a year, but when I saw this, my curiosity got the best of me and I thought I would try it. It has been a month or so since I made that mistake because now I can't find the check box that I checked to get it and I want to make it go away because it preempts all my Try/Catch block exception handlers. I don't get to see the messages that those Try/Catch blocks provide and I miss not having them.
Here is how I test by forcing a "General Exception" to Occur. In my application I have a method that interfaces to Microsoft Word 2007. When my application starts up it creates an instance of MS-Word and assigns it to a global object reference variable. If the user closes that instance of MS-Word by accident, which I have trained them not to do, my program will throw an exception because the object reference variable no longer points to an instance of an object. So I can force an exception by closing the instance of MS-Word and then execute a function that trys to create a document by using that instance of MS-Word that isn't there anymore. Please see attached code snippet.
The "Catch ex As Exception" never gets executed. Instead I get a dialog box provided by the .NET Framework, I assume that is where it is coming from, that has a title bar that exactly matches character for character the title bar of my application at the time the exception occurs. The content of that dialog box is: "Unhandled exception has occurred in your application. If you click Continue, the application will ignore this error and attempt to continue. If you click Quit, the application will close immediately."
"The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)."
In this context I assume that RPC stands for Remote Procedure Call. Which is the call my program was making to MS-Word. Unless I am wrong about this, I believe the solution to my problem is going to be a simple uncheck a check box some place in VS2005 IDE, but where? That is my question.
Public Sub PrintMMDoc_MS_Word(ByVal strMMDataDir As String, ByVal strMMDataFile As String, ByVal strMMDocDir As String, ByVal strMMDDocFile As String)
'2007-06-03 Ted Palmer
'Dim wrdApp As Word.Application: Instantiated in class frmLogin >> cmdLogin_Click event.
'Closed & Disposed in class MainMDIFrame >> Closing event
go_wrdApp.Visible = True
'2007-05-24 Ted Palmer
'This Try-Catch block uses MailMerge functionality of "Word.Application" to print an instance
'of the MS-word document passed as a parameter to this subroutine and
'the MailMerge data file passed as a parameter to this subroutine.
'Open an existing MailMerge Main document.
Dim wrdDoc As Object
wrdDoc = go_wrdApp.Documents.Open(FileName:=strMMDDocFile) '<-- MS-Word MailMergeMain document
wrdDoc.MailMerge.MainDocumentType = 0
strMMDataDir & strMMDataFile, ConfirmConversions:=False, _
ReadOnly:=False, LinkToSource:=True, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="", _
WritePasswordTemplate:="", Revert:=False, Format:=0, _
Connection:="", SQLStatement:="", SQLStatement1:="", SubType:=0)
.Destination = 0
.SuppressBlankLines = True
.FirstRecord = 1
.LastRecord = -16
Catch ex As Exception
MessageBox.Show("In Module MainModule >> Sub PrintMMDoc, there was an Error in the MailMerge process. " _
& "YOU the user probably caused this exception by closing the Microsoft Word application frame. " _
& "Please don't do this again. You probably did this during the Print Preview process. During that process. " _
& "you must close the MS-Word document and the MS-Word MailMerge Main document, but not the application frame. " _
& "When closing the MailMerge Main document, you will see 2 small x(s) in the upper right corner of the application " _
& "frame. Click ONLY the bottom x. Then minimize the application frame. To recover from this condition " _
& "and restore the printing subsystem, you must exit the AutoSubrogate(TM) program and restart it again. " _
& "Please save your work and restart the AutoSubrogate(TM) program now: " & ex.Message, _
"AutoSubrogate(TM) Exception:", MessageBoxButtons.OK, MessageBoxIcon.Stop)
End Sub 'PrintMMDoc_MS_Word