When C# was created, they decided that C++ was wrong when it came to try-catch. Instead, they took the Java approach and used try-catch-finally. The reason C++ doesn't have this block is because it's unnecessary: since acquisition is initialization, most resources are local. They'll be cleaned up automatically, getting destructor calls as the stack unwinds. In Java and C#, no such luck; thus, finally.

Dave has been cleaning up a lot of C# code recently and found the following, excellent example of finally being used. The real question is, "Finally what?"

 

  int changes = 0;

  try
  {
      changes =
Server.GetData(Convert.ToInt32(Status.Pending)).Results.Count;
  }
  finally{}

  try
  {
      changes += Server.GetVersion(Convert.ToInt32(Status.Pending)).Count;
  }
  finally{}

  try
  {
      changes += Server.GetOrder(Convert.ToInt32(Status.Pending));
  }
  finally{}

  if (changes > 0)
  {
      StringOutput += StartFont( System.Drawing.Color.Red );
  }

  StringOutput += changes.ToString();

 

If programming is a conversation, I feel like this one left me hanging.

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!