1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
using System;
public class TestTryFinally
{
static int result = 0;
public static void TrivialMain()
{
int i = 123;
string s = "Some string";
object o = s;
try {
// Illegal conversion; o contains a string not an int
i = (int) o;
}
finally {
Console.WriteLine("i = {0}", i);
result = i;
}
}
public static int Main()
{
try {
try {
TrivialMain();
}
finally {
Console.WriteLine("cleaning up");
}
}
catch(Exception) {
Console.WriteLine("catch expected exception");
result += 1;
}
if (result != 124)
return 1;
return 0;
}
}
|