#if DEBUG and the correct ways to implement it [closed]

I wonder what I should do in a situation given in the following example:

I built a condition, based on the preprocessor directive #if DEBUG. SonarQube says that the code never executes, but this is only true if the project is built in Release mode. My question is, should I simply ignore this warning or can I build such a construct otherwise? Should I put the #if debug around the throw and remove the debug variable in this case? What if I have a lot of code inside this #if #else ?

closed as off-topic by Peter Taylor, Pieter Witvoet, Denis, IEatBagels, Toby SpeightOct 11 at 14:35

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Peter Taylor, Pieter Witvoet, Denis, IEatBagels
If this question can be reworded to fit the rules in the help center, please edit the question.

• Questions about problems with code are off-topic here - we only review code that's already working as intended. Having that said, SonarQube is correct because of that debug = false; line. – Pieter Witvoet Oct 11 at 14:01
• I don't get your reaction. Isn't that site EXACTLY for this kind of problems? I cannot post this on StackOverflow, since it is a question about code quality, and not a programming problem. And this example IS working as intended, it just shows a warning. And I want to find out what people do in such a situation to get rid of the warning / do better code. – Amon Bune Oct 12 at 6:16
• So you're saying this piece of code really throws a NotImplementedException in debug mode? Even though debug is clearly set to false? – Pieter Witvoet Oct 12 at 7:25
• Okay, I haven't realized that. The combination of Visual Studio starting an old state of the code plus not clearly looking at the code. – Amon Bune 2 days ago