Exception on FormCreate is not thrown

270 Views Asked by At

By default any unhandled exception occurring in TForm.OnCreate will lead to an error message beeing shown instead of an exception beeing thrown.

The reason is this code in VCL.Forms:

function TCustomForm.HandleCreateException: Boolean;
begin
    Application.HandleException(Self);
    Result := True;
end;

All my forms inherit from TMyForm. I plan to override this function to solve the problem:

function TMyForm.HandleCreateException: Boolean;
begin
    Result := False;
end;

But I cannot imagine anybody wanting an exception on form creation to be swallowed, leaving a potentially halfly initialized form, yet this code still exists in VCL. This leaves me with the question:

Are there any reasons to not treat unhandled exceptions on form creation this way? Or are there better options to handle my problem?


Edited to clarify the original problem. I have the following code:

try
    //...
    Frm := TBooForm.Create(...);
    Frm.ShowModal;
    //...
except
    //exception in TBooForm.FormCreate not landing here.
end;

If I don't touch global exception handling, an unhandled exception in TBooForm.FormCreate() will not land in the exception block. Instead Frm will display in halfly initialized state, leading to hard to track errors.

0

There are 0 best solutions below