Bug 314936 (MONO59427) - [PATCH] Reachability of try with finally
Summary: [PATCH] Reachability of try with finally
Status: RESOLVED FIXED
Alias: MONO59427
Product: Mono: Compilers
Classification: Mono
Component: C# (show other bugs)
Version: unspecified
Hardware: Other Other
: P3 - Medium : Enhancement
Target Milestone: ---
Assignee: Mono Bugs
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-06-02 05:56 UTC by Ben Maurer
Modified: 2007-09-15 21:24 UTC (History)
1 user (show)

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments
proposed fix (402 bytes, patch)
2005-08-24 11:34 UTC, Thomas Wiest
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Wiest 2007-09-15 18:40:18 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".