开发者

Is it possible to mark code to be compiled only in debug mode?

I've got a try catch (or with in F#) structures all over the code but I don't really need them in debug mode, it's easer for me to debug errors via VS debugger.

So I want to mark try catch codelines to be compiled only in release mode - i开发者_运维知识库s it possible or not ?


You can surround them with:

#if !DEBUG
...
#endif


No one mentioned about ConditionalAttribute that could be applied to a code block. For a false condition the code block (and all it's calls) are skipped from compilation step.

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


What you are looking for are preprocessor commands like so:

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

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


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

#if DEBUG
#else
try
#endif

...

#if DEBUG
#else
with e -> ...
#endif


you can use #if preprocessor command

#if !DEBUG
try {
#endif
// your "exceptional" code
#if !DEBUG
} catch { }
#endif
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜