Throw and Catch an IO exception because the file zxcvb.data doesn't exist : Buildin Exceptions « Development Class « C# / C Sharp






Throw and Catch an IO exception because the file zxcvb.data doesn't exist

 

using System.IO;

public class IoError {
  public static void Main() {
    StreamReader f;
    try{
      f = new StreamReader("DoesNotExist.data");
    }catch(IOException e) {
      System.Console.WriteLine(e);
    }
    f = new StreamReader("DoesNotExist.data");
  }
}
           
         
  








Related examples in the same category

1.OutOfMemoryException Exception
2.StackOverflowException Exception
3.NullReferenceException Exception
4.InvalidCastException Exception
5.IndexOutOfRangeException Exception
6.OverflowException Exception
7.Throw Index Out Of Range Exception
8.Throw Null reference Exception
9.Throw Invalid Operation Exception
10.Argument Null Exception
11.Throw Argument Out Of Range Exception
12.ArgumentException is thrown when one of the arguments provided to a method is not valid.
13.OverflowException