开发者

Debug-Execution Adventure

I debugged my java code. It didn't give any errors.But when i executed it (it isn't giving errors either, but) the code didn't successfully terminate. This is very fu开发者_运维百科nny. But is that even possible?


sure, when the slowdown introduced by debugger does mask some race condition, but this normally only applies to multi-threading or networking code.


Yes it is possible that code works when debugging and doesn't work when running. Two possible reasons I can think of right now are

  • Concurrency in case of multithreading: if your debugger stops on a breakpoint, timing between multiple threads can change which can influence the behaviour
  • When debugging, you can trigger certain parts of the code multiple times (more than when it has been executed without debugging), like for example via the toString method or via doing inspects or having some watch expression configured


Yes, your code can be syntactically correct (and thus might run without any errors) but may be semantically incorrect.

Assume the following:

public int add( int operand1, int operand2)
{
   return operant1 - operand2;
}

This would run without errors but still be incorrect due to logic/implementation error.

So, it IS possible to get wrong results by otherwise smoothly running code.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜