Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Exercises

  1. “Using Trace.WriteLine() is preferable to using Debug.WriteLine() as the Debug version only works in debug builds.” Do you agree with this statement? Why?
  2. Provide code for a simple application containing a loop that generates an error after 5000 cycles. Use a breakpoint to enter Break mode just before the error is caused on the 5000th cycle (note: a simple way to generate an error is to attempt to access a nonexistent array element, such as myArray[1000] in an array with a hundred elements).
  3. finally code blocks only execute if a catch block isn't executed.” True or false?
  4. Given the enumeration data type orientation defined below, write an application that uses Structured Exception Handling (SEH) to cast a byte type variable into an orientation type variable in a safe way. Note that you can force exceptions to be thrown using the checked keyword, an example of which is shown below. This code should be used in your application:
    enum orientation : byte
    {
          north = 1,
          south = 2,
          east  = 3,
          west  = 4
    }
    myDirection = checked((orientation)myByte);

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint