Debug.Fail and Debug.Assert

I have a question about the Debug.Fail method that puzzles me. It from the MeassureUp test looks like this:

To increase the reliability of your code, you want to check the importance and stop execution if the value is not set properly. However, you want to stop execution only during debugging. You do not want users with release versions of your application to experience problems.

Which method should you use?

  • Debug.Assert (my answer)
  • Debug.Flush
  • Debug.Fail (correct answer according to MeassureUp test)
  • Debug.Indent

I answered Debug.Assert because it has a logical condition as a parameter, which means that it can check the value. Debug.Fail contains only strings as parameters for any message that should be displayed. But here is the official argument:

  • Debug.Fail causes the debugger to break into a line of code and displays an error message.
  • Debug.Assert evaluates the condition and displays a message, but does not interrupt processing.
  • Debug.Flush flushes the debug output buffer.
  • Debug.Indent controls the formatting of output.

What do they mean that Debug.Assert "does not interrupt processing"? Both Debug.Assert and Debug.Fail provide similar pop-ups with Abort, Retry, and Ignore buttons. In addition, Debug.Assert evaluates the expression.

Is the official answer wrong, including their reasoning, or am I not understanding something?

+7
source share
1 answer

There is simply no difference. Debug.Assert () calls Fail () when the condition is false. So there is no difference between Assert () and the if-statement that calls Fail ().

I suggest you find the best website.

+9
source

All Articles