does atl support try..catch block?(empty inside) 
Author Message
 does atl support try..catch block?(empty inside)

see the title.


Tue, 27 Jan 2004 09:50:45 GMT  
 does atl support try..catch block?(empty inside)
Yes! I use them all the time. (keyword version) I haven't
tried the macro's though.
Quote:
>-----Original Message-----
>see the title.

>.



Tue, 27 Jan 2004 11:33:33 GMT  
 does atl support try..catch block?(empty inside)
Hi,

If you want to use C++ exception handling in your ATL code, you app will
have to use statically linked startup code. This will increase your code
size (Note, if you want to use STL in your ATL code, you have to enalbe C++
exception handling). So, if you define _ATL_MIN_CRT preprocessor symbol,
you cannot use try-catch (or STL) in your ATL code, or you will get an link
error.

In COM programming, C++ exceptions thrown by your code cannot cross the
boundaries of your interface's method. So, it's recommneded to use
ISupportErrorInfo and IErrorInfo in your COM code. If you think you code
will throw an exception, please do catch it since these exceptions cannot
cross the boundaries. Please see below.

STDMETHODIMP CMyObject::Item(long index, IDispatch** ppItem)
{
    try
    {
    return m_itemList.at(index.iVal)->QueryInterface(
        IID_IDispatch, (void**)ppItem);
    }
    catch (std::out_of_range& error)
    {
        return Error(error.what());
    }

Quote:
}

Thanks,
Kelton


Tue, 27 Jan 2004 13:50:03 GMT  
 does atl support try..catch block?(empty inside)
Hi,

Using C++ exception handling (try and catch block) needs C Run-Time (CRT)
startup code. If you prefer to using _ATL_MIN_CRT preprocessor definition
to minimize the image size and the reliance on run-time DLLs, you can
choose SEH (structured exception handling), __try, and __except. For more
information about SEH, please refer to these links:

Handling Exceptions in C and C++, Part 2
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnde...
l/deep060399.asp

Q166480 INFO: Active Template Library (ATL) Frequently Asked Questions
http://support.microsoft.com/support/kb/articles/q166/4/80.asp

Note: COM doesn't allow you to throw an exception out of an object with the
intention of it being caught by a client. If you throw a C++ exception in
an EXE-packaged server, the most likely result is that the server will die.
If you throw an exception in a DLL-packaged server, then it is possible
that the client will be able to catch the exception but this behavior is
regarded as antisocial and is strongly discouraged. C++ exceptions are
language dependent and COM objects are language neutral. Therefore, in this
situation, using HRESULTs or considering IErrorInfo, ISupportErrorInfo is
more appropriate, read this article in MSDN:

Propagate Error Info: Use ATL and C++ to Implement Error-Handling COM
Objects

Thanks,
Freist



Wed, 28 Jan 2004 01:13:11 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. The if ~ else block in try~catch block

2. TRY-CATCH vs. try-catch

3. try/catch VS TRY/CATCH

4. Optimizer ignores try-catch block

5. try catch block

6. Overhead of try-catch blocks?

7. /Og causes intermittent omission of try..catch block

8. nested try/catch block and _set_se_translator

9. try{} catch{} block and Global Optimization

10. Error processing using try-catch blocks

11. can I nest try/catch blocks?

12. ??true==false inside a try catch loop??

 

 
Powered by phpBB® Forum Software