Bugzilla – Bug 314936
[PATCH] Reachability of try with finally
Last modified: 2007-09-15 21:24:23 UTC
---- Reported by bmaurer@users.sf.net 2004-06-01 22:56:26 MST ---- class T { static int Main () { try { } finally { throw new System.Exception ("..."); } } } The end of this method is not reachable, so the error `Not all code paths return a value' is incorrect. ` The end point of a try statement is reachable if both of the following are true: · The end point of the try block is reachable or the end point of at least one catch block is reachable. · If a finally block is present, the end point of the finally block is reachable. ' From 15.10 The try statement ---- Additional Comments From miguel@ximian.com 2004-06-07 01:26:41 MST ---- But in your sample, the end of finally will not be reachable. When does this happen, and why do we need to fix this? ---- Additional Comments From bmaurer@users.sf.net 2004-06-07 07:38:03 MST ---- Miguel, "But in your sample, the end of finally will not be reachable." *exactly* "It is a compile-time error for the end point of the block of a function member that computes a value to be reachable. If this error occurs, it typically is an indication that a return statement is missing." -- 15.1 Since the end of the `finally' block is not reachable, the end of the method is not reachable, so it does not violate this rule. ---- Additional Comments From miguel@ximian.com 2004-09-20 13:44:46 MST ---- Well, the compiler is expecting that a value is returned here, since you have an `int' result in your main. Either you return a value, or change it to void. Am closing this bug. ---- Additional Comments From bmaurer@users.sf.net 2004-09-20 14:45:11 MST ---- This isnt correct. The following method static int Foo() { throw new NotImplementedException (); } Happens alot in our code. Because of the reasons I cited in the spec, it is a valid method. Likewise, static void Foo () { try {} finally {throw new NotImplementedException (); } } is valid. } ---- Additional Comments From atsushi@ximian.com 2005-08-24 04:34:59 MST ---- Created an attachment (id=166156) proposed fix ---- Additional Comments From rharinath@novell.com 2006-05-03 10:58:36 MST ---- Should be fixed in SVN r60220. Imported an attachment (id=166156) Unknown operating system unknown. Setting to default OS "Other".