Re: Warning: Unreachable code detected
Mike Andrews <[email protected]> Mon, 12 Nov 2007 11:21:54 -0600
| Newsgroups | gmane.comp.windows.devel.dotnet.winforms |
|---|---|
| Message-ID | <[email protected]> |
In the case of switch statements, you don't need a break for a preceding throw or return statement. On Nov 12, 2007 11:14 AM, R. Rogers <[email protected]> wrote: > 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/ <http://www.richardrogers.ca/> >