开发者

Exception location in DelphiXE not correctly located in the debugger?

The debugger does not locate the line of the exception开发者_如何学运维, its either to deep or to late.

Code:

procedure LoadLogo;
const
  RES_APP_LOGO = 'AppAboutLogo';
var
  resourceStream : TResourceStream;
begin
  try
    resourceStream := TResourceStream.Create( HInstance, RES_APP_LOGO, RES_TYPE_FXRESOURCES );
    resourceStream.Position := 0;
    ImageLogo.Picture.Bitmap.LoadFromStream(resourceStream); //---> causes exception (A)
    Refresh();
  finally
    FreeAndNil(resourceStream);    
  end;
end;

procedure TForm.Initialize;
begin

  //do something....

  LoadLogo(); //(C)

  AnotherFunction();  //<----- debugger points here (B)

end; 

procedure TForm.CreateCreate(Sender : TObject);
begin
  Initialize();
end;

On an exception at location (A), with "Use Debug DCUs" = false, the debugger points to (B), the line outside the function called after the exception occurred. With "Use Debug DCUs = true", it breaks in a generic Exception thrower in Graphics.pas. The exception class is fine, the location is not correct or useful from a debugging perspective - neither the calling location (C) nor the real cause point (A) is located.

This requires looking at the call stack to step back to the cause which does not seem right.

Any ideas?


When you are using debug DCUs you need to use the call stack to see how execution reached the throw. There's no way for the debugger to break any earlier than the point at which the exception is raised.

Without debug DCUs the debugger can only break at a line of code for which it has debug information. That has to be somewhere in your code.


In my experience if the stopping position appears mismatched from the breakpoint, you have a problem with visibility of the source code, i.e it has got out of step with the compilation. It is also very easy to accidentally open a (slighlty different) copy of the source in the IDE - that seems to confuse the IDE and if often stops in that window having compiled from another window.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜