Is it possible to mark code for compilation only in debug mode?

I have a catch try (or with F #) structure throughout the code, but I don’t need them in debug mode, this makes it easier for me to debug errors using the VS debugger.

So, I want try catch tags to be compiled only in release mode - is this possible or not?

+4
source share
5 answers

You can surround them:

#if !DEBUG ... #endif 
+7
source

What you are looking for are preprocessor commands:

 #if !DEBUG try { #endif code(); #if !DEBUG } catch(Exception) { dostuff(); } #endif 

MSDN article: http://msdn.microsoft.com/en-us/library/4y6tbswk.aspx

+4
source

! is not a preprocessor directive in F #, so you will need to do:

 #if DEBUG #else try #endif ... #if DEBUG #else with e -> ... #endif 
+3
source

No one mentioned ConditionalAttribute , which can be applied to code. For a false condition, a block of code (and all its calls) is skipped from the compilation stage.

Refer: https://msdn.microsoft.com/en-us/library/system.diagnostics.conditionalattribute(v=vs.110).aspx

+3
source

you can use the #if preprocessor command

 #if !DEBUG try { #endif // your "exceptional" code #if !DEBUG } catch { } #endif 
+2
source

All Articles