🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #3559

Re: To Catch Exception incide of COM Automation Object

#3559
From: Remy Lebeau (TeamB)
Date: Sat, 27 May 2006 20:39
34 lines
2108 bytes
"Dmitry Konnov" <dmitry@weblinedesign.biz> wrote in message
news:447835f3@newsgroups.borland.com...

> I want to trace all Exceptions inside my COM object.

COM methods are not allowed to let exceptions pass into the application.  To
do so is undefined behavior, since the COM object has no way to know what
programming language is being used to access the object, and that language
may not be able to handle the exception properly at all (VB can't handle
Delphi exceptions, etc).  Every COM method that you expose access to for the
application to call should have its own try..catch block inside of itself,
ie:

    HRESULT __stdcall TMyIntfImpl::DoSomething()
    {
        try
        {
            // do the work here ...
        }
        catch(const Exception &e)
        {
            return Error(E.Message.c_str(), IID_IMyIntf, E_UNEXPECTED);
        }
        return S_OK;
    }

This way, if an exception occurs inside a COM method, the Error() method
will assign values that the application can retreive via the IErrorInfo
interface.  You can then focus your debugging in that particular method to
narrow down why it crashed in the first place.


Gambit
Technical Details
Message-ID: <4478b9bd$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newshub.sdsu.edu!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <447835f3@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,d7caffc31d3abad7
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <447835f3@newsgroups.borland.com>
Subject: Re: To Catch Exception incide of COM Automation Object
Date: Sat, 27 May 2006 13:39:57 -0700
Lines: 36
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 68.69.17.41
Message-ID: <4478b9bd$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1148762557 68.69.17.41 (27 May 2006 13:42:37 -0700)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newshub.sdsu.edu!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail