[shell-coding] Re: try() catch()

Do your string loading/formatting before the try/catch.  If there wasn't
an exception, clean up the memory allocation.  If there was, show your
message box (it should be fine to use your IError object).  If your
catch block falls through as it does below, you're fine.  If you need to
return, just cleanup before doing so.
 
It'll waste a little memory on the short term, but it's safe.
 
BTW, I don't understand a lot about C++ exceptions.. what is object
unwinding and how does it affect exception handling?
 
- Visigoth

-----Original Message-----
From: shell-coding-bounce@xxxxxxxxxxxxx
[mailto:shell-coding-bounce@xxxxxxxxxxxxx] On Behalf Of
Bgvinyard@xxxxxxx
Sent: Monday, January 20, 2003 9:20 PM
To: shell-coding@xxxxxxxxxxxxx
Subject: [shell-coding] try() catch()


Ok... im not too sure on this so thought i would get some expert help...


given this:

class Localization
{
public: 
        Localization();
        ~Localization();
        
        void LoadLanguage(LANGID wLanguageID);
        int LoadString(UINT uID, LPTSTR ptzBuffer, size_t cchMax);
        int MessageBox(HWND hWnd, UINT uText, UINT uCaption, UINT
uType);
        int MessageBox(HWND hWnd, LPCTSTR ptzText, UINT uCaption, UINT
uType);
        
private:
        HINSTANCE m_hRes;
        LANGID m_wLanguageID;
};

I want to do something like this:

try
{
        ...
}
catch(...)
{
        TCHAR tzError[MAX_LINE_LENGTH];
        Localization lError;
        
        if (lError.LoadString(IDS_MODULEINITEXCEPTION_ERROR, tzError,
MAX_LINE_LENGTH))
        {
                TCHAR tzErrorEx[MAX_LINE_LENGTH];
                StringCchPrintf(tzErrorEx, MAX_LINE_LENGTH, tzError,
iter->first.c_str());
                lError.MessageBox(NULL, tzErrorEx,
IDS_LITESTEP_TITLE_ERROR);
        }                                                       
}

I'm not sure this would affect object unwinding because its withing the
catch block, unless 
the code within the catch block throws an exception... any comments?
suggestions?

Thanks
Message 

Other related posts: