Skip to content
September 15, 2013 / windperson

Compiler Error CS0157

Here is an intesting C# interview question:


What’s the resulting return value of this method?

int TryExceptionHandling()
{
	try
	{
		throw new Exception();
		return 0;
	}
	catch(Exception ex)
	{
		int ret = 1;
		return ret;
	}
	finally
	{
		int ret = 2;
		return ret;
	}
}

Actually, this code Won’t Be Compiled!
The C# compiler will generate Compiler Error CS0157:
http://msdn.microsoft.com/en-us/library/0hbbzekw.aspx
That is, we can not using some sort of “escape mechanism” (return, goto) to quit the finally block statement execution.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: