Programming Homework

Submitted by: Submitted by

Views: 114

Words: 302

Pages: 2

Category: Science and Technology

Date Submitted: 10/14/2013 05:42 PM

Report This Essay

1. For each of the following methods determine if it compiles and if not, explain why:

A.

private void MethodA()

{

try

{

//some instructions here

}

catch (Exception ex)

{

//some instructions here

}

}

Compile

B.

private void MethodB()

{

try

{

//some instructions here

}

catch

{

//some instructions here

}

finally

{

//some instructions here

}

}

Compile

C.

private void MethodC()

{

try

{

//some instructions here

}

finally

{

//some instructions here

}

}

Compile

D.

private void MethodD()

{

try

{

//some instructions here

}

}

Not compile A try statement means that you believe something can go wrong, and the catch says that you can adequately handle that which you catch.

2. Consider this method:

private void Method2()

{

try

{

System.Console.WriteLine("Inside Try");

return;

}

finally

{

System.Console.WriteLine("Inside Finally block");

}

}

What would the program write into the console?

The program would write into the console:

Inside Try

Inside Finally block

3. Consider this method:

private void Method3()

{

try

{

int n1 = 0;

int n2 = n1 / n1 ;

System.Console.WriteLine("Inside Try");

return;

}...