Wednesday, June 3, 2009

Exception Handling

1. Intermixing program and error-handling logic:
A) increase a program's performance, because the program does not need to perform tests to determine whether the task executed correctly and the next task can be performed.
B) should be used in place of exception handling where possible.
C) can degrade a program's performance, because the program must perform (potentially frequent) tests to determine whether the task executed correctly and the next task can be performed.
D) None of the above.

Points Earned: 1.0/1.0
Correct Answer(s): C




2. Which of the following is not included in an exception's stack trace?
A) A descriptive message for the exception.
B) Instructions on handling the exception.
C) The method-call stack at the time the exception occurred.
D) The name of the exception.

Points Earned: 1.0/1.0
Correct Answer(s): B




3. Which of the following statements about try blocks is true?
A) The try block should contain statements that may throw an exception.
B) The try block must be followed by a finally block.
C) The try block should contain statements that may process an exception.
D) The try block must be followed by at least one catch block.

Points Earned: 1.0/1.0
Correct Answer(s): A




4. In C#, after an exception is handled, control resumes ____. This is known as the ____ model of exception handling.
A) just after the throw point, termination
B) after the last catch block, resumption
C) after the last catch block, termination
D) just after the throw point, resumption

Points Earned: 1.0/1.0
Correct Answer(s): C




5. Exceptions can occur:
A) from C#'s CLR
B) through explicitly mentioned code in a try block
C) through calls to other methods made in a try block
D) All of the above

Points Earned: 1.0/1.0
Correct Answer(s): D




6. What is the difference between a try block and a try statement?
A) There is no difference; the terms can be used interchangeably.
B) The try block refers to the keyword try followed by a block of code. The try block and its corresponding catch and/or finally clauses together form a try statement.
C) The try statement refers to the keyword try followed by a block of code. The try statement and its corresponding catch and/or finally clauses together form a try block.
D) A try statement refers to the block of code following the keyword try, while the try block refers to the try keyword and the block of code following this keyword.

Points Earned: 1.0/1.0
Correct Answer(s): B




7. In C#, try blocks are used for:
A) resolving exceptions.
B) testing code.
C) testing for infinite loops.
D) testing for exceptions.

Points Earned: 1.0/1.0
Correct Answer(s): D




8. Which of the following is not true regarding the throw point of an exception?
A) It specifies the point at which the exception must be handled.
B) It is the initial point at which the exception occurs.
C) It is specified as the top row of the method-call stack at the time the exception occurred.
D) All of the above statements are true.

Points Earned: 1.0/1.0
Correct Answer(s): A




9. If exception handling code is not nested, exceptions caught are in the _________.
A) finally block
B) throws block
C) try block
D) catch block

Points Earned: 1.0/1.0
Correct Answer(s): C




10. Which of the following statements is not true?
A) Exception handling can only catch the exception but cannot resolve the exception.
B) Exception handling enables programmers to write robust and fault-tolerant programs.
C) Exception handling can resolve exceptions.
D) There are many ways of handling exceptions.

Points Earned: 1.0/1.0
Correct Answer(s): A




11. Exception handling statements typically consist of:
A) if statements and throw blocks.
B) try blocks, catch blocks, and finally blocks.
C) try blocks, throw blocks, and finally blocks.
D) try blocks and catch blocks.

Points Earned: 1.0/1.0
Correct Answer(s): B




12. An exception is:
A) the way a computer signals to the users that it is about to terminate
B) something that the computer does not understand
C) a problem a computer has during construction
D) a problem that a program has during runtime

Points Earned: 1.0/1.0
Correct Answer(s): D




13.
In the catch block below, what is e?


catch ( DivideByZeroException e )
{
Console.WriteLine( e );
} // end catch


A) The type of the exception being caught
B) The name of catch block's exception parameter
C) An exception handler
D) A finally block

Points Earned: 1.0/1.0
Correct Answer(s): B




14. An uncaught exception:
A) is an exception that occurs for which there are no matching catch clauses.
B) is another term for a thrown exception.
C) is a possible exception that never actually occurs during the execution of the program.
D) is an exception that occurs for which the matching catch clause is empty.

Points Earned: 1.0/1.0
Correct Answer(s): A




15. Catch blocks that do not specify an exception type or an identifier ____________.
A) is an error
B) cannot catch any exceptions
C) can catch any exceptions
D) None of the above

Points Earned: 1.0/1.0
Correct Answer(s): C




16. With programming languages that do not support exception handling, which of the following happens?
A) programmers often delay writing error-processing code
B) programmers somethings forget to include error-processing code
C) programmers write less robust software products
D) All of the above

Points Earned: 1.0/1.0
Correct Answer(s): D




17. When an exception occurs it is said to have been:
A) declared
B) caught
C) handled
D) thrown

Points Earned: 1.0/1.0
Correct Answer(s): D




18. A FormatException is used to handle:
A) extra spaces input by the user
B) errors with deleting a file from disk
C) wrong data type inputs
D) all of the above

Points Earned: 1.0/1.0
Correct Answer(s): C




19. Re-throwing exceptions is used to:
A) catch even more errors in the program.
B) provide addition debugging information.
C) prevent the program from terminating from a fatal error.
D) All of the above

Points Earned: 1.0/1.0
Correct Answer(s): B




20. When an exception occurs, the try block _______.
A) expires
B) continues until a matching catch block
C) continues until the end of the try block
D) None of the above

Points Earned: 1.0/1.0
Correct Answer(s): A




21. User-defined exceptions should be derived from the:
A) ApplicationException class.
B) SystemException class.
C) Exception class.
D) ConsoleException class.

Points Earned: 1.0/1.0
Correct Answer(s): C




22. Which of the following statements is true?
A) The throw statement is used to throw an exception.
B) The throw statement is used to specify that a method will throw an exception.
C) The throw statement is used to access an exception parameter.
D) All of the above.

Points Earned: 1.0/1.0
Correct Answer(s): A




23. Which of the following statements is true?
A) The code in a finally block is executed only if an exception occurs.
B) The code in a finally block is executed only if an exception does not occur.
C) The code in a finally block is executed only if there are no catch blocks.
D) None of the above are true.

Points Earned: 1.0/1.0
Correct Answer(s): D




24. Which of the following statements is false?
A) The finally block and try block can appear in any order.
B) A finally block is optional.
C) A finally block should release all resources acquired in the corresponding try block.
D) A finally block is placed after the last catch block.

Points Earned: 1.0/1.0
Correct Answer(s): A




25. Which of the following is not a property of Exception?
A) Source
B) PrintError
C) HelpLink
D) TargetSite

Points Earned: 1.0/1.0
Correct Answer(s): B




26. The process that attempts to locate an appropriate catch handler for an uncaught exception is known as:
A) laddering
B) stack winding
C) stack unwinding
D) stack traversing

Points Earned: 1.0/1.0
Correct Answer(s): C




27. User-created exceptions can be created by:
A) overriding the Error class.
B) overriding the Exception property.
C) extending class Exception.
D) they cannot be created

Points Earned: 1.0/1.0
Correct Answer(s): C




28. The catch handler that catches an exception of type Exception should be
A) a catch handler that catches an exception of type Exception should not be used
B) last
C) anywhere
D) first

Points Earned: 1.0/1.0
Correct Answer(s): B




29. After a finally block has finished executing:
A) control returns to the throw point.
B) the application exits.
C) control proceeds to the first statement after the last catch block.
D) control proceeds to the first statement after the finally block.

Points Earned: 1.0/1.0
Correct Answer(s): D




30. Which of the following is true about the using statement?
A) It simplifies writing code in which you obtain a resource.
B) It only works with objects that implements from the IDisposable interface.
C) It implicitly places the code in a try block with a corresponding finally block that contains the object's Dispose method.
D) All of the above

Points Earned: 1.0/1.0
Correct Answer(s): D




31. According to Microsoft, programmer-defined exceptions should contain 3 constructors:
A) a default constructor, a constructor that receives a string for the error message and a constructor that receives an Exception argument of the inner exception object
B) a default constructor, a constructor that receives a string and a constructor that receives both a string and an exception
C) a constructor that receives a string, a constructor that receives an exception and a constructor that receives both
D) a default constructor, a constructor that receives a string and a constructor that receives a number indicating the line number where the exception occurred

Points Earned: 1.0/1.0
Correct Answer(s): B




32. If an exception is thrown in a catch handler, any code in the handler that follows the thrown exception will:
A) generate a logic error
B) generate a syntax error
C) never be executed
D) run after the finally block is done

Points Earned: 1.0/1.0
Correct Answer(s): C




33. In order to display the error message generated by an exception to the user, the programmer uses:
A) the Message property of class Exception
B) the ErrorMessage method of class Exception
C) the ErrorMessage property of class Exception
D) the Message method of class Exception

Points Earned: 1.0/1.0
Correct Answer(s): A




34. In order to tell the user what happened in an exception one must
A) pop the exception
B) toss the exception
C) throw the exception
D) access Exception properties

Points Earned: 1.0/1.0
Correct Answer(s): D




35.
Which of the following statements is true after a catch block is entered to handle an exception?


A. A catch block can rethrow an exception that it has not handled.
B. A catch block can rethrow an exception that it has partially handled.
C. A rethrown exception may be handled by an exception handler list after the enclosing try block.
D. A catch block cannot rethrow an exception that it has completely handled.


A) All of the above
B) B, C, D
C) A, B, C
D) A, B

Points Earned: 1.0/1.0
Correct Answer(s): C




36. The structure of exception handling varies from programmer to programmer.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




37. In many cases, handling an exception allows a program to automatically restart execution of the program from the beginning.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




38. Exception-handling reduces the likelihood that errors will be overlooked, thus making programs more robust.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




39. A NullReferenceException is thrown when there is an attempt to use a reference that points to nothing.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




40. Exception handlers typically access objects declared within their try blocks to determine the causes of the exceptions.A) True
B) False

Points Earned: 0.0/1.0
Correct Answer(s): False




41. If not done properly, exception handling can lead to resource leaks.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




42. Almost all runtime exceptions can usually be fixed by eliminating coding errors.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




43. Exceptions can only be handled one at a time.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




44. All exceptions cause the program to terminate when thrown.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




45. If an exception handler is to catch a variety of exceptions, use a comma-separated list of catch arguments in the catch handler.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




46. Exception handling was first implemented by Andrew Koenig and Bjarne Stroustrup.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




47. After an exception has occurred and a stack trace has been printed, the program may exit or continue executing, depending on the circumstances.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




48. A particularly severe problem could prevent a program from continuing normal execution, instead requiring the program to notify the user of the problem before terminating in a controlled mannerA) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




49. Variables local to try blocks are usable in the corresponding catch and finally blocks.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




50. The base class for all exception classes is System.Exception.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




51. C# throws an IntegerArithmeticException when division by zero in integer arithmetic occurs.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




52. There has to be a catch clause for every expected exception type.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




53. Exceptions are used by implementing class Exception.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




54. Using inheritance with exceptions enables an catch block to catch related exceptions using a concise notation.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




55. The Message property of an exception is what is displayed to the user should that exception be thrown.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




56. Read the .NET Framework classes' documentation for a detailed description of what Exceptions are thrown.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




57. The finally block is only executed if no error was reached in the try block.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




58. C# does not guarantee that a finally block (if one is present) will be executed if a try block is exited via a return, break or continue statement.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




59. If a finally block appears after the last catch block, it is executed only if an exception is thrown.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




60. The finally block is an ideal location for code that releases resources to prevent "resource leaks."A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




61. As a rule of thumb all user-defined exceptions should end with Exception in their name.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




62. There can be no code in between try/catch/finally blocks.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




63. Each Exception should have three constructors: A default one, one that receives a string and one that receives a string and an exception.
A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




64. The InnerException property is used to handle implemented exception cases.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




65. C#'s exception handling mechanism keeps error-processing code in the main line of a program's code to improve program clarity.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




66. Stack unwinding is the process that attempts to locate an appropriate catch handler for an uncaught exception.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




67. After the last catch block, the required finally block provides code that always executes regardless of whether or not an exception occurs.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




68. Resource de-allocation should be done explicitly in the finally block.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




69. The StackTrace property keeps track of all the method calls that occur in a program, and that is how a program knows which method caused the error.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




70. User defined exceptions are used to handle user defined objects.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




71. The constructor method for an exception class should be overloaded to allow the customizing of the display message.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True

No comments:

Post a Comment