Warning: Unreachable code detected

"R. Rogers" <[email protected]> Mon, 12 Nov 2007 12:14:36 -0500
Newsgroups gmane.comp.windows.devel.dotnet.winforms
Message-ID <006801c8254f$80a65e50$6800a8c0@Speedster>
Hi,

I like coding defensively, and correct me if I'm wrong, but I think the
following code demonstrates this to a very small degree:

            switch (code)
            {
                case 1:
                    result = DialogResult.OK;
                    break;

                case 2:
                    result = DialogResult.Cancel;
                    break;

                case 3:
                    throw new ApplicationException("No such logon
session.");
                    break;

        ...
        }

The trouble is that if I break after throwing an exception, the compiler
gives me an "unreachable code detected" message, and I don't like any
warnings.

Would you have any advice to share on this? I don't really want to get rid
of the break statement.

Best regards,

Richard Rogers
http://www.RichardRogers.ca/