, , . #, , . , , . , , , .
, . , , , . , . , .
, C# , .
. C# .
System. Exception
C# . C# Exception, System. , Exception.
Exception SystemException. , C# (.. CLR). SystemException Exception, .
.NET Framework , SystemException. , DivideByZeroException. , C# , Exception.
C# : try, catch, throw finally. , . . . .
|
|
, , try. try , . - , catch. , , . throw. , try, finally.
try catch
C# try catch. . try/catch :
try {
// , .
} catch (ExcepTypel exOb) {
// ExcepTypel. }
catch (2 exOb) {
// 2. }
. try, catch, . catch. , , catch, , , . , exOb .
exOb . , , , . . , , exOb .
, , , , try , catch . , catch. , catch , .
, . , . , CLR IndexOutOfRangeException, .NET Framework. .
// .
Using System;
class ExcDemol {
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 ");
}
catch (IndexOutOfRangeException) {
// .
Console.WriteLine(" !");
}
Console.WriteLine(" .");
}
}