Handling Exceptions on form Creation

I have a MDI application and sometimes I’m running into problems (AV’s, OutofResource errors, etc) when trying to create new child forms.  Currently, the way it is being handled is as follows:

    try
        frmSomeForm := TfrmSomeForm.Create(Application);
    except
        CleanupClientEnvironment;
        nNdx:= 1;
        while nNdx <= 5 do
        begin
              try
                  frmSomeForm:=TfrmSomeForm.Create(Application);
                  nNdx:= 10;
              except
                  CleanupClientEnvironment;
                  inc(nNdx);
              end;
        end;
        if frmSomeForm = nil then
        begin
             CleanupClientEnvironment;
             frmSomeForm := TfrmSomeForm.Create(Application);
        end;
   end;

As you can see it is attempting to recreate the form a number of times,  freeing up resources each time, before finally giving up.

Now from what I can gather from this previous thread:
http://groups.google.com/groups?hl=en&lr=&threadm=3fe6f715%40newsgroups.borland.com&rnum=1&prev=/groups%3Fhl%3Den%26lr%3D%26selm%3D3fe6f715%2540newsgroups.borland.com   (I’d use tinyurl, but it appears to be broken)

The try…except here shouldn’t even be happening if there’s a exception in the form creation.  Is that correct?  Is there a better way to handle this problem?  Any input is greatly appreciated.
pjegeAsked:
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.

Ivanov_GCommented:
0
ChristianRocherCommented:
Hi,

In delphi, the FormCreate evant is protected by a try/except block that eats the exception.
I you want to get exceptions during the creation of the form then overrides the Create
constructor of the form and move your code in this place.

Cio.
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
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
Delphi

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.