Exceptions
String s = "b";
int.Parse(s);
List<int> listOfInts = new List<int>();
StreamReader sr = new StreamReader("c:\does_not_exist.txt");
List<String> someList = new List<String>();
someList.Count
int x = 5 / 0;
List<String> teamList = new List<String>();
teamList.Add("example1");
teamList.Add("example2");
try
{
Console.WriteLine("hi there");
} catch(Exception e)
{
Console.WriteLine("ERROR");
}
hi there
List<int> listOfInts = new List<int>();
int firstInt = listOfInts[1];
static void ThrowsAnException()
{
int zero = 0;
int y = 3 / zero;
Console.WriteLine("I just tried to divide by zero");
}
static void Main(string[] args)
{
try
{
ThrowsAnException();
}
catch(DivideByZeroException e)
{
Console.WriteLine("ERROR: You tried to divide by zero");
}
}
ERROR: You tried to divide by zero
List<int> listOfInts = new List<int>();
listOfInts.Add(3);
listOfInts.Add(2);
listOfInts.Add(1);
foreach(int i in listOfInts)
{
Console.WriteLine(i);
}