Exam Prep Questions

Question 1

You are creating a data import utility for a personal information system you recently designed. When the record in the source data file is not in the required format, the application needs to throw a custom exception. You want to keep the name of this exception class as InvalidRecordStructureException . Which of the following classes would you choose as the base class for the custom exception class?

  • A. ApplicationException

  • B. Exception

  • C. SystemException

  • D. InvalidFilterCriteriaException

A1:

Answer A is correct. When you create a class for handling custom exceptions in your programs, the best practice is to derive it from the ApplicationException class. Answer B is incorrect because the Exception class is the base class for both the ApplicationException and SystemException classes and should not be derived from. Answer C is incorrect because the SystemException class represents the exceptions raised by the CLR and is used for system-defined exceptions. Answer D is incorrect because InvalidFilterCriteriaException is thrown when a filter criteria is not valid and it is not suitable as a base class for the exception defined in the question.

Question 2

You are required to debug a program that contains exception-handling code. To understand the program better, you've created a stripped-down version of it and included some Response.Write statements to give you a clue about the flow of its execution. The program has the following code:

 try {     int num = 100;     int den = 0;     Response.Write("Message1" + "<br>");     try     {         int res = num/den;         Response.Write("Message2" + "<br>");     }     catch(ArithmeticException ae)     {         Response.Write("Message3" + "<br>");     } } catch(DivideByZeroException dbze) {     Response.Write("Message4" + "<br>"); } finally {     Response.Write("Message5" + "<br>"); } 

Which of the following options describes the correct order of displayed messages?

  • A.

     Message1 Message2 Message3 Message4 Message5 
  • B.

     Message1 Message3 Message5 
  • C.

     Message1 Message4 Message5 
  • D.

     Message1 Message2 Message4 Message5 
A2:

Answer B is correct. When an exception occurs in a try block, the program searches for a matching catch block associated with that try block. In all cases, the finally block is executed. Answers A and D are incorrect because, when an exception occurs, the control jumps from the try block to a matching catch block and the string Message2 never gets displayed. Answer C is incorrect because the ArithmeticException type is more general than the DivideByZeroException and therefore all DivideByZeroException exceptions are handled in the catch block that catches the ArithmeticException .

Question 3

What is the output displayed by the Label lblResult control in the following code segment?

 try {    try    {        throw new ArgumentOutOfRangeException();    }    catch(ArgumentException ae)    {        throw new ArgumentException("Out of Range", ae);    } } catch(Exception ex) {    lblResult.Text = ex.InnerException.GetType().ToString(); } 
  • A. System.Exception

  • B. System.ApplicationException

  • C. System.ArgumentException

  • D. System.ArgumentOutOfRangeException

A3:

Answer D is correct. The label displays the System.ArgumentOutOfRangeException exception because the inner catch block caught this exception and wrapped it in the InnerException property of the newly thrown exception. Answers A and C are incorrect because, although these two types are the base types of the System.ArgumentOutOfRangeException type, the GetType() method returns the exact runtime type of the current instance. Answer B is incorrect because System.ArgumentOutOfRangeException is a system exception instead of an application exception.

Question 4

You are designing a global time-entry system for a multinational company. It will be an ASP.NET application served over the Internet through the company's Web server. You are designing an error-handling mechanism for this application and want the application to show a customized error page for all HTTP errors. All unhandled exceptions caused by ASP.NET pages within your application should be logged in the Web server's event log; all other applications on the Web server should remain unaffected. You want a solution that requires minimum modifications. Which of the following places will be your preferred places to write this code? (Select two.)

  • A. web.config

  • B. global.asax

  • C. In the ASPX page, using the Page directive

  • D. machine.config

A4:

Answers A and B are correct. The customized error page for HTTP errors can be shown using the <error> element in the web.config file. To catch all unhandled exceptions in an application, the Application_Error() event handler in the global.asax file needs to be programmed. Answer C is incorrect because, if you use the ErrorPage attribute of the Page directive, you will have to modify (and in the future, maintain) all the pages within your ASP.NET application. Answer D is incorrect because, if you use the <error> element in the machine.config file, all the ASP.NET applications on the Web server will be affected.

Question 5

You have developed a global time-entry system for a multinational company. The system is an ASP.NET application served over the Internet through the company's Web server in New York. The first phase of testing is being performed in the Los Angeles office, where it has been reported that users are getting default ASP.NET error pages instead of customized error pages. Which of the following actions do you need to take to enable custom error pages for those users? (Select two.)

  • A. Set the mode attribute of the <customErrors> element in the web.config file to On .

  • B. Set the mode attribute of the <customErrors> element in the web.config file to Off .

  • C. Set the mode attribute of the <customErrors> element in the web.config file to RemoteOnly .

  • D. Set the defaultRedirect attribute of the <customErrors> element in the web.config file to the location of the custom error page.

A5:

Answers C and D are correct. To set the custom error page, you need to set the defaultRedirect attribute to the location of the custom error page, and to enable custom error pages for the Los Angeles testing team, you must set the mode attribute to RemoteOnly . Answer A is incorrect because, when the mode attribute of the <customErrors> element is set to On , custom error pages are enabled for all the users. Answer B is incorrect because, when the mode attribute of the <customErrors> element is set to Off , custom error pages are disabled for all the users.

Question 6

You need to create a custom exception class in your Web application. You have written the following code for the exception class:

 public class KeywordNotFound:     ApplicationException {    public KeywordNotFoundException()       {       }    public KeywordNotFoundException(        string message, Exception inner)       : base(message, inner)       {       } } 

Upon peer review of the code, it was found that you did not follow some of the best practices for creating a custom exception class. Which of the following suggestions do you need to incorporate ? (Select all that apply.)

  • A. Name the exception class KeywordNotFoundException .

  • B. Derive the exception class from the base class Exception instead of ApplicationException .

  • C. Add one more constructor to the class with the following signature:

     public KeywordNotFoundException(      string message) : base(message) { } 
  • D. Add one more constructor to the class with the following signature:

     public KeywordNotFoundException(    Exception inner) : base(inner) { } 
  • E. Derive the exception class from the base class SystemException instead of ApplicationException .

A6:

Answers A and C are correct. As a good exception handling practice, you should end the name of the exception class with the word Exception . In addition, an exception class must implement three standard constructors. The missing constructor is the one given in Answer C. Answers B and E are incorrect because, for custom exceptions, you should derive the custom exception class from the ApplicationException base class. Answer D is incorrect because the given constructor is not a standard constructor.

Question 7

In your ASP.NET application, you are opening a file. You want to close the file regardless of an exception in the program. Which of the following code blocks can help you achieve this? (Select all that apply.)

  • A. try

  • B. catch

  • C. finally

  • D. using

A7:

Answers C and D are correct. You can use both finally and using for this purpose because the finally block is executed regardless of whether the exception occurs and the using statement ensures that the allocated resources in the statement are properly disposed. Answer A is incorrect because the try block is used to enclose those statements that might throw an exception. Answer B is incorrect because the catch block is used to write those statements that might handle an exception.

Question 8

You want to capture all exceptions that escape from the exception-handling code in your application and log them to the system event log. You want a solution that requires minimum coding efforts. Which of the following techniques would you use?

  • A. Program the Application_End() event handler in the global.asax file.

  • B. Program the Page_Unload() event handler of the Page class.

  • C. Program the Page_Error() event handler of the Page class.

  • D. Program the Application_Error() event handler in the global.asax file.

A8:

Answer D is correct. You need to handle unhandled exceptions in the Error events. Because you need to trap exceptions for the complete application, the Application_Error() event handler is the best place to trap exceptions. Answer A is incorrect because the Application_End() event handler is invoked only when the application quits. Answers B and C are incorrect because these event handlers need to be programmed for each page and require additional coding efforts.

Question 9

The structured exception-handling mechanism of the .NET Framework allows you to handle which of the following types of exceptions? (Select all that apply.)

  • A. Exceptions from all CLS-compliant languages

  • B. Exceptions from non-CLS-compliant languages

  • C. Exceptions from unmanaged COM code

  • D. Exceptions from unmanaged non-COM code

A9:

Answers A, B, C, and D are correct. The .NET Framework allows you to handle all types of exceptions, including cross-language exceptions for both CLS- and non-CLS-compliant languages. It also allows you to handle exceptions from unmanaged code ”both COM and non-COM.

Question 10

Which of the following statements is true regarding the following code?

 const int someVal1 = Int32.MaxValue; const int someVal2 = Int32.MaxValue; int result; checked {    result = someVal1 * someVal2; } 
  • A. The code generates an OverflowException .

  • B. The code executes successfully without any exceptions.

  • C. The code causes a compile-time error.

  • D. The code executes successfully, but the value of the variable result is truncated.

A10:

Answer C is correct. When constant values are inside the checked block, they are checked for overflow at compile time. Answers A, B, and D are incorrect because you are multiplying two maximum possible values for an integer and the result certainly could not be stored inside an integer. The compiler detects this and generates a compile-time error.



MCAD Developing and Implementing Web Applications with Visual C#. NET and Visual Studio. NET (Exam [... ]am 2)
MCAD Developing and Implementing Web Applications with Visual C#. NET and Visual Studio. NET (Exam [... ]am 2)
ISBN: 789729016
EAN: N/A
Year: 2005
Pages: 191

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net