views:

526

answers:

3

Hi,

If I run a program and an exception is raised I am asked if I want to continue or break.

If I choose break I can see where the exception is coming from but if the break is in a library or system file not one of my source files (Say the exception is in System.pas or Controls.pas) I need to manuall step the execution forward using F8 until it returns to one of my files, so I can see what part of my code caused the exception.

This can take a long time.

I know I should be catching lower level exceptions in my code but in this instance it's not hitting one of my exception handlers.

Is there a way to say 'run foward with execution until you get to file X' or 'until you get back into a project specific file'.

I'm also interested out of general curiosity on how other compilers / IDEs handle this.

Apologies if I haven't made this as clear as a I should.

Cheers Sam H

+10  A: 

You can solve this by using your stack view.

  1. Open your stack view. (CTRL+ALT+S)
  2. Double click on the method in the stack view where you wish to place a breakpoint.
  3. The unit containing the caller method opens and is positioned on the caller method.
  4. Place your breakpoint.
Lieven
+3  A: 

There are several ways:

  1. Use the "Next source line" function (Shift+F7)
  2. Use the call stack and double-click on the function you need, add a breakpoint there and hit "Run" (F9).
  3. Use the "Step out" (Shift+F8) function until you are back into your own code.
DR
I have a German version of Delphi, so I'm not exactly sure about that menu caption for Shift+F7...
DR
I think F5 is to set breakpoint in code and F9 is to run in Delphi. Which version of Delphi do you use?
Yogi Yang 007
Doh, it's D2005, but right now I'm using VB6
DR
+4  A: 

There's an even simpler way than Lieven's suggestion. Follow the first 3 steps as he laid them out, but don't place a breakpoint.

The problem with placing a breakpoint is that you have to clear it afterwards or you'll end up getting dropped into the debugger every time you pass that line. If you only want to run to a certain line and then drop to the debugger once, put the cursor on that line (the insertion point, not the mouse cursor) and press F4 (Run to Cursor). It's like a one-time breakpoint.

Mason Wheeler
@Mason, the problem is that the OP doesn't know which line of code triggered the exception. This makes using F4 not a viable solution.
Lieven
I don't quite understand. The OP can't find a line to hit F4 on, but they can find a line to set a breakpoint on?
Mason Wheeler
He doesn't find a line to set a breakpoint on. Delphi's "break on exception" is enabled. It's Delphi who stops at "a" line. OP's problem was that Delphi stops in a system unit io a "user" unit.
Lieven
I understand that. I mean, basically, follow your steps, but instead of setting a breakpoint at step 4, just hit F4 instead. Edited the post to clarify this.
Mason Wheeler
+1 @Mason, sorry I misread. You are right offcourse. Using F4 as step 4 io setting a breakpoint is indeed simpler.
Lieven