Tải bản đầy đủ (.docx) (44 trang)

05 BTNB quiz3 exception handling utilities

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (123.75 KB, 44 trang )

Part 1 of 2 - Part 1

Question 1 of 20

65.0/ 75.0 Points

5.0/ 5.0 Points

The _____ encloses the statements that might throw an exception whereas catch handles an exception
if one exists.

A. Try

B. Catch

C. Finally

D. Exception

Question 2 of 20

A____block enclose the code that could throw an exception.

A. Exception

B. Error

5.0/ 5.0 Points


C. Catch



D. Try

Question 3 of 20

5.0/ 5.0 Points

Sam is developing an application that enables the users to perform read and write operations on text
tiles. He uses structured exception handling to handle the errors. He writes the code for closing all the
files that were opened in the finally block. Which of the following is true regarding the finally block?

A. Finally block is used to enclose code that needs to run, regardless of whether an exception is
raised
B. Finally block is executed only when no error occurs

C. Finally block will be executed only if an error occurs

D. . Finally block is executed after Catch block when no error occurs

Question 4 of 20

using System;
class Test
{
public static void Main()

0.0/ 5.0 Points


{

int value =Int32.Parse(""99953"");
double dval=Double.Parse(""1.3433E+35"");
Console.WriteLine(value);
Console.WriteLine(dval);
}
};
What will be the output of above code when compiled / run?

A. The output of above code will be
99953
1.3433E+35
B. The output of above code will be
99953
1.3433E35
C. The code will not generate a compile time
error.
D. The code will generate a compile time error.

Question 5 of 20

What is the output ? :
class Program
{
static void Main(string[] args)
{
int number = 1;

5.0/ 5.0 Points



try
{
number = 2;
return;
}
catch (Exception)
{
}
finally
{
number = 3;
}
Console.WriteLine(number);
Console.ReadLine();
}
}

A. 3

B. 2

C. 1

D. nothing

Question 6 of 20

What wrong with these code :
try


5.0/ 5.0 Points


{
intNumber = int.Parse(strNumber);
}
catch (Exception ex)
{
Console.WriteLine(""Can't convert the string to "" + ""a number: "" + ex.Message);
}

A. You should catch System.Exception or System.SystemException in a catch block because you
could inadvertently hide run-time problems like Out Of Memory.
B. no thing wrong!

C. Do Not Catch Exceptions That You Cannot Handle

D. Syntax error

Question 7 of 20

A method_____an exception when that method detects that a problem has occured.

A. Trys

B. Throws

5.0/ 5.0 Points



C. Catches

D. a and b

Question 8 of 20

5.0/ 5.0 Points

What wrong with this code
try {
// exception generating code
} catch(Exception e)
{
// Do nothing
}

A. Throwing exceptions is expensive. Do not use exceptions to control application flow. If you can
reasonably expect a sequence of events to happen in the normal course of running code, you probably
should not throw any exceptions in that scenario
B. You should never catch System.Exception or System.SystemException in a catch block because
you could inadvertently hide run-time problems like Out Of Memory.

C. Do not catch exceptions that you do not know how to handle and then fail to propagate the
exception


Question 9 of 20

5.0/ 5.0 Points


What wrong with these code :
double result = 0;
try
{
result = numerator/divisor;
}
catch( System.Exception e)
{
result = System.Double.NaN;
}

A. Syntax error

B. This code is not good, you should Use validation code to avoid unnecessary exceptions.

C. no thing wrong!

D. Do Not Catch Exceptions That You Cannot Handle

Question 10 of 20

What wrong with this code
static void ProductExists( string ProductId)
{ //... search for Product
if ( dr.Read(ProductId) ==0 )
// no record found, ask to create

5.0/ 5.0 Points



{
throw( new Exception(""Product Not found""));
}
}

A. Do not catch exceptions that you do not know how to handle and then fail to propagate the
exception
B. You should never catch System.Exception or System.SystemException in a catch block because
you could inadvertently hide run-time problems like Out Of Memory.
C. Throwing exceptions is expensive. Do not use exceptions to control application flow. If you can
reasonably expect a sequence of events to happen in the normal course of running code, you probably
should not throw any exceptions in that scenario

Question 11 of 20

What is the output :
class Program
{
static void Main(string[] args)
{
int number = 0;
try
{
number = number++;
}
catch (Exception)
{
number++;

0.0/ 5.0 Points



}
finally
{
number++;
}
Console.WriteLine(number);
Console.ReadLine();
}
}

A. 1

B. Syntax error

C. 2

D. 3

Question 12 of 20

5.0/ 5.0 Points

_______ block is executed after try block regardless of the occurrence of error. _____ block contains all
cleanup codes. For example, if there is no need of open connection to the database after try block we
can write code for connection close in _____ block.


A. Try


B. Exception

C. Catch

D. finally

Question 13 of 20

5.0/ 5.0 Points

A catch clause may catch exception of which type?

A. The Error Type

B. The Exception Type.

C. The Throwable Type

Question 14 of 20

Exception objects are derived from the class.

5.0/ 5.0 Points


A. Event

B. Catch


C. Exception

D. Try

Question 15 of 20

A____block enclose the code that could throw an exception.

A. Error

B. Catch

C. Exception

D. Try

5.0/ 5.0 Points


Part 2 of 2 - Part 2

20.0/ 25.0 Points

Question 16 of 20

5.0/ 5.0 Points

The Syntax of a predefined Sort method is:

A. System.Array.Sort(Arraytosort)


B. System.Array.Sort()

C. Arraytosort.Sort()

D. Arraytosort.Array.Sort()

Question 17 of 20

5.0/ 5.0 Points

Select a collection type that match all condition bellow :
Represents a collection of key/value pairs that are organized based on the hash code of the key.
A weakly typed collection of key-value pairs.
Lets you quickly get an object out of the collection by using it's key.
Access items in your weakly typed collection, based on a key, not on an index.
Each element is a key/value pair stored in a DictionaryEntry object

A. HashTable Class


B. Queue Class

C. Stack Class

D. Array class

Question 18 of 20

5.0/ 5.0 Points


Select a collection type that match all condition bellow :
It is One of the most basic collection classes.
It's not really a collection class, due to its limitations and its not even located in the System.Collections
namespace, but in the System namespace.
It has a fixed size.
it can have multiple dimensions.
You can access an item of it by it's index.

A. Array class

B. HashTable Class

C. Queue Class


D. Stack Class

Question 19 of 20

5.0/ 5.0 Points

Select a collection type that match all condition bellow :
A SortedList object internally maintains two arrays to store the elements of the list; that is, one array for
the keys and another array for the associated values.
Each element is a key/value pair that can be accessed as a DictionaryEntry object.
A key cannot be a null reference, but a value can be.
The elements of a SortedList object are sorted by the keys.
In either case, a SortedList does not allow duplicate keys.
When an element is added, it is inserted into SortedList in the correct sort order, and the indexing

adjusts accordingly

A. Queue Class

B. SortedList Class

C. Array class

D. HashTable Class

Question 20 of 20

0.0/ 5.0 Points


How can you sort the elements of the array in descending order?

A. By calling Sort() and then Reverse() methods.

B. By calling SortReverse()

C. By calling Descend()

D. By calling ReverseSort();

Part 1 of 2 - Part 1

Question 1 of 20

70.0/ 75.0 Points


5.0/ 5.0 Points

The _____ encloses the statements that might throw an exception whereas catch handles an exception
if one exists.

A. Try

B. Catch

C. Finally


D. Exception

Question 2 of 20

5.0/ 5.0 Points

A____block enclose the code that could throw an exception.

A. Exception

B. Error

C. Catch

D. Try

Question 3 of 20


5.0/ 5.0 Points

Sam is developing an application that enables the users to perform read and write operations on text
tiles. He uses structured exception handling to handle the errors. He writes the code for closing all the
files that were opened in the finally block. Which of the following is true regarding the finally block?

A. Finally block is used to enclose code that needs to run, regardless of whether an exception is
raised


B. Finally block is executed only when no error occurs

C. Finally block will be executed only if an error occurs

D. . Finally block is executed after Catch block when no error occurs

Question 4 of 20

using System;
class Test
{
public static void Main()
{
int value =Int32.Parse(""99953"");
double dval=Double.Parse(""1.3433E+35"");
Console.WriteLine(value);
Console.WriteLine(dval);
}
};

What will be the output of above code when compiled / run?

A. The output of above code will be
99953
1.3433E+35
B. The output of above code will be
99953

0.0/ 5.0 Points


1.3433E35
C. The code will not generate a compile time
error.
D. The code will generate a compile time error.

Question 5 of 20

What is the output ? :
class Program
{
static void Main(string[] args)
{
int number = 1;
try
{
number = 2;
return;
}
catch (Exception)

{
}
finally
{
number = 3;
}
Console.WriteLine(number);
Console.ReadLine();
}
}

5.0/ 5.0 Points


A. 3

B. 2

C. 1

D. nothing

Question 6 of 20

5.0/ 5.0 Points

What wrong with these code :
try
{
intNumber = int.Parse(strNumber);

}
catch (Exception ex)
{
Console.WriteLine(""Can't convert the string to "" + ""a number: "" + ex.Message);
}

A. You should catch System.Exception or System.SystemException in a catch block because you
could inadvertently hide run-time problems like Out Of Memory.
B. no thing wrong!


C. Do Not Catch Exceptions That You Cannot Handle

D. Syntax error

Question 7 of 20

5.0/ 5.0 Points

A method_____an exception when that method detects that a problem has occured.

A. Trys

B. Throws

C. Catches

D. a and b

Question 8 of 20


What wrong with this code
try {
// exception generating code
} catch(Exception e)
{
// Do nothing

5.0/ 5.0 Points


}

A. Throwing exceptions is expensive. Do not use exceptions to control application flow. If you can
reasonably expect a sequence of events to happen in the normal course of running code, you probably
should not throw any exceptions in that scenario
B. You should never catch System.Exception or System.SystemException in a catch block because
you could inadvertently hide run-time problems like Out Of Memory.

C. Do not catch exceptions that you do not know how to handle and then fail to propagate the
exception

Question 9 of 20

What wrong with these code :
double result = 0;
try
{
result = numerator/divisor;
}

catch( System.Exception e)
{
result = System.Double.NaN;
}

A. Syntax error

5.0/ 5.0 Points


B. This code is not good, you should Use validation code to avoid unnecessary exceptions.

C. no thing wrong!

D. Do Not Catch Exceptions That You Cannot Handle

Question 10 of 20

5.0/ 5.0 Points

What wrong with this code
static void ProductExists( string ProductId)
{ //... search for Product
if ( dr.Read(ProductId) ==0 )
// no record found, ask to create
{
throw( new Exception(""Product Not found""));
}
}


A. Do not catch exceptions that you do not know how to handle and then fail to propagate the
exception
B. You should never catch System.Exception or System.SystemException in a catch block because
you could inadvertently hide run-time problems like Out Of Memory.


C. Throwing exceptions is expensive. Do not use exceptions to control application flow. If you can
reasonably expect a sequence of events to happen in the normal course of running code, you probably
should not throw any exceptions in that scenario

Question 11 of 20

What is the output :
class Program
{
static void Main(string[] args)
{
int number = 0;
try
{
number = number++;
}
catch (Exception)
{
number++;
}
finally
{
number++;
}

Console.WriteLine(number);
Console.ReadLine();
}
}

5.0/ 5.0 Points


A. 1

B. Syntax error

C. 2

D. 3

Question 12 of 20

5.0/ 5.0 Points

_______ block is executed after try block regardless of the occurrence of error. _____ block contains all
cleanup codes. For example, if there is no need of open connection to the database after try block we
can write code for connection close in _____ block.

A. Try

B. Exception

C. Catch


D. finally


Question 13 of 20

5.0/ 5.0 Points

A catch clause may catch exception of which type?

A. The Error Type

B. The Exception Type.

C. The Throwable Type

Question 14 of 20

Exception objects are derived from the class.

A. Event

B. Catch

C. Exception

5.0/ 5.0 Points


×