Hi,

Scenario:
I build a UDP connection.
Within a try{} block I connect, send and receive.
Now on exceptions or invalid messages, I 'return' an error code, thus effectively exiting the method.
To clean up the connection, I want to close it.

The question here is whether I should close it before every 'return' action, or simply close it in the finally{} block.

I made the following test-case, but I'm wondering whether this is a reliable test.
Code:
		static void Main(string[] args)
		{
			try
			{
				//throw new IndexOutOfRangeException();
				return;
			}
			catch (IndexOutOfRangeException)
			{
				return;
			}
			finally
			{
				Console.WriteLine("Reached finally");
				Console.Read();
			}
		}
The result of this test is that it writes 'Reached finally' whether I throw an exception or just 'return'.

I'm just a bit surprised that even if I return, it runs the finally{} block.
Is this expected behavior?

Thanks.