Bug 27535 - Switch case throwing exception can't be compiled without "unreachable code" warning
Summary: Switch case throwing exception can't be compiled without "unreachable code" w...
Status: RESOLVED FIXED
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: 3.12.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2015-03-01 02:15 UTC by Kevin Chen
Modified: 2015-03-02 08:29 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Kevin Chen 2015-03-01 02:15:14 UTC
When compiling switch statements with a case that throws an exception, the line marked "A" will give an unreachable code warning. However, if A is removed, B will give a fall-through error even though there is no fall through due to the exception. 

So it is not possible to compile this piece of code cleanly (without warnings or errors). 

int num = ...;
switch (num)
{
case 0:
    throw new NotImplementedException();
    break;     // Line A
case 1:        // Line B
    DoSomething();
    break;
}
Comment 1 Marek Safar 2015-03-02 08:29:44 UTC
Already fixed in master and mono 4.0