.


:




:

































 

 

 

 


finally.




// finally.

Using System;

class UseFinally {

public static void GenException(int what) { int t;

int[] nums = new int [2];

Console.WriteLine(" " + what); try {

switch(what) { case 0:

t = 10 / what; // - break; case 1:

nums[4] =4; // break; case 2:

return; // try

}

}

catch (DivideByZeroException) {

Console.WriteLine(" !"); return; // catch

}

catch (IndexOutOfRangeException) {

Console.WriteLine(" .");

}

finally {

Console.WriteLine(" try.");

class FinallyDemo { static void Main() {

for(int i=0; i < 3; i++) {

UseFinally.GenException(i);

Console.WriteLine();

}

}

}

.

try.

1

.

try.

2

try.

, finally try.

: finally try, catch . , finally try, catch. finally try, .

Exception

, . , catch . . , Exception, . Exception .

Exception . : Message, StackTrace Targetsite. . Message , ; StackTrace , , get Site , , .

, Exception . ToString (), . , , WriteLine ().

Exception .

// Exception.

Using System;

class ExcTest {

public static void GenException() {

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]);

}

Console.WriteLine("He ");

}

}

class UseExcept {

static void Main() { try {

ExcTest.GenException();

}

catch (IndexOutOfRangeException exc) {

Console.WriteLine(" : ");

Console.WriteLine(exc); // ToStringO Console.WriteLine(" StackTrace: " + exc.StackTrace);

Console.WriteLine(" Message: " + exc.Message);

Console.WriteLine(" TargetSite: " + exc.TargetSite);

}

Console.WriteLine(" .");

}

}





:


: 2016-12-03; !; : 399 |


:

:

,
==> ...

1589 - | 1351 -


© 2015-2024 lektsii.org - -

: 0.009 .