Visual Studio .NET Tips & Tricks

Helpful information for Visual Studio .NET developers

Tip: Treat Warnings as Errors

Posted by Ion Toma on April 16, 2006

A warning is a bug in waiting*. Warnings may be acceptable for debug builds, but for a release build, warnings must be always treated as errors. Zero-warnings should be as a rule for programmers, it is easy to ignore warnings, some of them may actually indicate a problem.
Warnings are the compiler's way of saying "this bit of code looks wrong, you better check it out“*. 

Others reasons:

  • It is bad practice to ship code that has compiler warnings in it. The compiler can help the developer, if the compiler generates an warning that means the developer must pay attention to it.
  • The customer may get some examples which contains sources. The warnings generated during compilation make the code look sloppy.

How to set it up: from Project Settings> Configuration Properties select the build setting and change the “treat warnings as errors” settings to true.Then set the warning levels to full, since we want to get all the help from the compiler as possible.

Warnings - Image 3

* http://discuss.fogcreek.com/joelonsoftware4/default.asp?cmd=show&ixPost=133392&ixReplies=21

Advertisements

2 Responses to “Tip: Treat Warnings as Errors”

  1. I have always tried to program without warnings but find that with C# this is a little difficult in one respect. Let’s assume that in a block of code I wish to suppress a particular error that I expect may happen but allow other errors to return up to a higher error handler. I might code something like this;

    try
    {

    }
    catch (ExceptionX e)
    {
    // deliberately suppressing this exception
    }

    This code compiles without errors and works as I want. It does however generate a compile-time warning because I am not using the ExceptionX variable e.

    Does anyone know how I can achieve the desired result without getting a compile-time warning?

  2. Ion Toma said

    See if the information found at the following address can help:

    http://haacked.com/archive/2006/06/07/ExamineAnExceptionInACatchBlock.aspx

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: