Chapter 10: Exception Handling
Chapter 10: Exception Handling
Exception Handling
Structures
struct oStates
{
String sAbbrev = "";
String sName = "";
String sBird = "“;
int nPopulation = 0;
}
oStates[] myStates = new oStates[50];
try {
int zero = 0;
int val = 100 / zero;
val = val + 1;
}
catch (DivideByZeroException ex)
{
throw new DivideByZeroException("Please don't
try to divide by zero !!", ex);
}
Exception Class
1 System.IO.IOException
Handles I/O errors.
2 System.IndexOutOfRangeException
Handles errors generated when a method refers to an array index
out of range.
3 System.ArrayTypeMismatchException
Handles errors generated when type is mismatched with the array
type.
4 System.NullReferenceException
Handles errors generated from referencing a null object.
Exception Class
5 System.DivideByZeroException
Handles errors generated from dividing a dividend with zero.
6 System.InvalidCastException
Handles errors generated during typecasting.
7 System.OutOfMemoryException
Handles errors generated from insufficient free memory.
8 System.StackOverflowException
Handles errors generated from stack overflow.