PART I
C h a p t e r 1 3 :
E x c e p t i o n H a n d l i n g
341
PART IPART I
Console.WriteLine("this won't be displayed");
}
}
class ExcDemo2 {
static void Main() {
try {
ExcTest.GenException();
}
catch (IndexOutOfRangeException) {
// Catch the exception.
Console.WriteLine("Index out-of-bounds!");
}
Console.WriteLine("After catch block.");
}
}
This program produces the following output, which is the same as that produced by the
first version of the program shown earlier:
Before exception is generated.
nums[0]: 0
nums[1]: 1
nums[2]: 2
nums[3]: 3
Index out-of-bounds!
After catch block.
As explained, because
GenException( )
is called from within a
try
block, the exception that
it generates (and does not catch) is caught by the
Do'stlaringiz bilan baham: |