.
nums[0]:
nums[1]: 1
nums[2]: 2
nums[3]: 3
!
.
, GenException () try, , catch Main (). GenException (), Main ().
, , : . , - . , , . , . , .
// C# .
Using System;
class NotHandled { static void Main() {
int[] nums = new int[4];
Console.WriteLine(" .");
// , for (int i=0; i < 10; i++) {
nums[i] = i;
Console.WriteLine("nums[{0}]: {1}", i, nums[i]);
, .
: System.IndexOutOfRangeException:
, NotHandled.Main() <_ >: 16
NotHandled. Main () System. IndexOutOfRangeException, .
, , , ! .
, , catch. . , catch, DivideByZeroException, . , IndexOutOfRangeException, catch, .
// !
Using System;
class ExcTypeMismatch { static void Main() {
int[] nums = new int [4];
try {
Console.WriteLine(" .");
|
|
// , for(int i=0; i < 10; i++) {
nums[i] = i;
Console.WriteLine("nums[{0}]: {1}", i, nums[i]);
}
Console.WriteLine("He ");
}
/* DivideByZeroException, . */ catch (DivideByZeroException) {
// .
Console.WriteLine(" !");
}
Console.WriteLine(" .");
}
}
.
.
nums[0]:
nums[1]: 1
nums[2]: 2
nums[3]: 3
: System.IndexOutOfRangeException:
ExcTypeMismatch.Main() <_ >: 18