Catch and try


I am fairly new working under a windows environment, and even newer to work with COMs, so apologize for any mistake I could make.

I am trying to program an application using Borland 5 that would connect to an Excel document, do some operations and retrieve the results. This is some sort of practice for me.

Also, I am trying to make this application a little bit robust, so before trying to open Excel, I am checking if its not already active, and only if not I open it. My code is this:

try{//Try to retrieve the application, if not opened, this would normally throw an error
vMSExcel = Variant::GetActiveObject("Excel.Application");
catch(...)//Catch the error throwned because Excel is not opened
try//Try to open Excel
vMSExcel = Variant::CreateObject("Excel.Application");
catch(...)//Excel seems not to be installed
ShowMessage("Unable to open Excel. Please make sure you have it installed");

I have implemented this code in a button.
Now, when I compile, there are no warnings or error, but when I click the button, the problem I encouter is that the error created by GetActiveObject is not throwned (when the application is closed). Rather, a dialog box pops-up and tells it has received an error from EOleSysError and that the process is stopped. My first catch block is thus completely ignored.

Any thoughts/advices/help on this would be much appreciated,



Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion