Skip to main content

Empty finally block

In This Article

CodeRush Classic shows the Empty finally block code issue if a finally block is empty.

#Fix

Add code to the empty finally block.

#Purpose

Empty finally block directs your attention to empty finally blocks, because it often denotes incomplete code.

#Example

public void SendData(Socket socket, byte[] data)
{
  NetworkStream netStream = new NetworkStream(socket);
  try
  {
    netStream.Write(data, 0, data.Length);
  }
  finally
  {

  }
}

Fix:

public void SendData(Socket socket, byte[] data)
{
  NetworkStream netStream = new NetworkStream(socket);
  try
  {
    netStream.Write(data, 0, data.Length);
  }
  finally
  {
    netStream.Dispose();
  }
}