System.Exception—catch an ArgumentNullException


Jump to: navigation, search
C# Code Snippets

C# Source Code Bank

See also …
edit

This C# code snippet first causes and then catches an ArgumentNullException.

using System;
 
class ArgumentNullExceptionExample
{
   public static void Main()
   {
      String[] stringArray = null;
      String delimiter  = " ";
      try
      {
         String s = String.Join (delimiter, stringArray);
      }
      catch (ArgumentNullException e)
      {
         Console.WriteLine ("Exception: {0}", e);
      }
   }
}


 ArgumentNullException example (program output)
Exception: System.ArgumentNullException: Value cannot be null.
Parameter name: value
at System.String.Join(String separator, String[] value)
at ArgumentNullExceptionExample.Main() in Program.cs:line 8


Personal tools