.


:




:

































 

 

 

 


, catch, DivideByZeroException, IndexOutOfRangeException.




-

, . , . , DivideByZeroException. , . , - . "", .

// .

Using System;

class ExcDemo3 {

static void Main() {

int[] numer = { 4, 8, 16, 32, 64, 128 };

int[] denom = { 2, 0, 4, 4, 0, 8 };

for(int i=0; i < numer.Length; i++) {

try {

Console.WriteLine(numer[i] + " / M +

denom[i] + M +

numer[i]/denom[i]);

}

catch (DivideByZeroException) {

// .

Console.WriteLine(" !");

}

}

}

}

.

2

!

16/4 4 32/4 8 -!

16

: , . try for, , . .

catch

try catch. . catch . , .

// catch.

Using System;

class ExcDemo4 {

static void Main() {

// numer denom.

int[] numer = { 4, 8, 16, 32, 64, 128, 256, 512 };

int[] denom = { 2, 0, 4, 4, 0, 8 };

for(int i=0; i < numer.Length; i++) {

try {

Console.WriteLine(numer[i] + " / " +

denom[i] + " " + numer[i]/denom[i ]);

}

catch (DivideByZeroException) {

Console.WriteLine(" !");

}

catch (IndexOutOfRangeException) {

Console.WriteLine(" .");

}

}

}

}

.

2

!

16/4 4 32/4 8 !

16 .

.

, catch .

, catch . catch, . catch .

. catch, . .

catch {

//

}

"" , .

"" . , , IndexOutOfRangeException DivideByZeroException, . .

// "" .

Using System;

class ExcDemo5 {

static void Main() {

// numer denom.

int[] numer = { 4, 8, 16, 32, 64, 128, 256, 512 };

int[] denom = { 2, 0, 4, 4, 0, 8 };

for (int i=0; i < numer.Length; i++) {

try {

Console.WriteLine(numer[i] + " / " +

denom[i] + " " + numer[i]/denom[i]);

}

catch { // "" .

Console.WriteLine (" .");

}

}

}

}





:


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


:

:

, , . , .
==> ...

1581 - | 1416 -


© 2015-2024 lektsii.org - -

: 0.009 .