NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

try-catch-finally

A common usage of catch and finally together is to obtain and use resources in a try block, deal with exceptional circumstances in a catch block, and release the resources in the finally block.

Example

// try-catch-finally
using System;
public class EHClass {
   public static void Main () {
      try {
         Console.WriteLine("Executing the try statement.");
         throw new NullReferenceException();
      }
      catch(NullReferenceException e) {
         Console.WriteLine("Caught exception #1."); 
      }
      catch {
         Console.WriteLine("Caught exception #2.");
      }
      finally {
         Console.WriteLine("Executing finally block.");
      }
   }
}

Output

Executing the try statement.
Caught exception #1.
Executing finally block.

See Also

C# Keywords | Compare to C++ | Exception Handling Statements | throw | Grammar