Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 392
  • Last Modified:

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.
0
pjege
Asked:
pjege
2 Solutions
 
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now