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?
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

0
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
0
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

0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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

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

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
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.