Debug-Execution Adventure

点点圈 提交于 2019-12-13 03:40:50

问题


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 funny. But is that even possible?


回答1:


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




回答2:


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



回答3:


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.



来源:https://stackoverflow.com/questions/5910926/debug-execution-adventure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!