tags:

views:

32

answers:

2

For example, the flash platform provides the flash.debugger.enterDebugger() API call that does the job:

if (some_cond())
{
    ...
}
else
{
   enterDebugger();
}

In that case, if some_cond() evaluates to false and we're in a debug session (it does nothing if we're in a normal session), then the execution will be halted at the line where enterDebugger is invoked and control given to the debugger, as if a breakpoint was set at that line.

I've looked at the android.os package but found nothing like it. Throwing an exception does the job of giving the control to the debugger, but then the code execution cannot be resumed at the spot where the exception was thrown.

A: 
if (someCond()) { .... }

else {
    android.os.Debug.waitForDebugger();
}

See android.os.Debug.

Al
I've already tried the waitForDebugger call, but all it does is block and wait until the debugger has been attached to the application if it was not already done.
Simon
+1  A: 

Java debugging supports suspending on exceptions. You could write:

void enterDebugger() {
  try {
    throw new DebugException();
  }
  catch (DebugException e) { //no-op
  }
}

And setup your IDE to suspend on caught exceptions of type DebugException.

Visser
Yes, it does what I want. Thanks. And I will add the waitForDebugger before the throw to make sure the debugger is ready to handle the catch.
Simon