Information Technology Reference
In-Depth Information
Diagnostic Directives
Diagnostic directives produce programmer-defined compile-time warning and error
messages.
The following is the syntax of the diagnostic directives. The messages are strings, but
notice that unlike normal C# strings, they do not have to be in quotes.
#warning
Message
#error
Message
When the compiler reaches a diagnostic directive, it writes out the associated message.
The diagnostic directive messages are listed by the compiler along with any compiler-
generated warning and error messages.
For example, the following code shows an
#error
directive and a
#warning
directive.
The
#error
directive is inside an
#if
construct, so that it will be generated only if the con-
ditions on the
#if
directive are met.
The
#warning
directive is a reminder to the programmer to come back and clean up a
section of code.
#define RightHanded
#define LeftHanded
#if RightHanded && LeftHanded
#error Can't build for both RightHanded and LeftHanded
#endif
#warning Remember to come back and clean up this code!