how to use exception handle in CStringArray

it's runtime error founded. How to use exception handle in CStringArray.
Please give me appropriate solution to execute error free. i thank try/catch is not to be supported.

CStringArray str;

      str.Add(L"abc");
      str.Add(L"xyz");

      CString str1;

      str1 = str.GetAt(1);
      try
      {
            str1 = str.GetAt(2);
      }
      catch(...)
      {
            TRACE("Error");
      }  
RuhelaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
The problem is that you are trying to catch a SEH exception (see http://msdn.microsoft.com/en-us/library/ms680657%28VS.85%29.aspx - "Structured Exception Handling"), which will not work with a C++ 'catch()'. In that case, the following should work:
CStringArray str;

      str.Add(L"abc");
      str.Add(L"xyz");

      CString str1;

      str1 = str.GetAt(1);
      __try
      {
            str1 = str.GetAt(2);
      }
      __except(1)
      {
            TRACE("Error");
      }

Open in new window

RuhelaAuthor Commented:
when i mention  __try/__except then give a compilation error.
l have also changes to "Yes With SEH Exceptions (/EHa)" in Enable c++ exception in settings.

error C2712: Cannot use __try in functions that require object unwinding
jkrCommented:
Um, yes, that's indeed true - yet SEH is still the only way to catch an access violation. The following should however compile:
CString TestGetAt(CStringArray* p)
{
      __try
      {
            return p->GetAt(2);
      }
      __except(1)
      {
            TRACE("Error");
      }

  return "Error";
}

CStringArray str;

      str.Add(L"abc");
      str.Add(L"xyz");

      CString str1;

      str1 = str.GetAt(1);

Open in new window

PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

RuhelaAuthor Commented:
In this time same compilation error found...

 error C2712: Cannot use __try in functions that require object unwinding
Deepu AbrahamR & D Engineering ManagerCommented:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RuhelaAuthor Commented:
thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.