CSCI-E237, Fall 2010
Homework Assignment 2
Due by Tues Sep 25, 2359 ET

.NET Framework, part 2

1. Create a new exception class called SecureCommunicationException. Think carefully about what its base class should be, and defend your choice in a comment to the TA, placed in a "readme.txt" file contained in the project. Just "it's what everyone else does", or "Microsoft recommends it" won't cut it. (In the latter case, I guarantee that one group at Microsoft recommends it and another group doesn't.) This will be the class that signals all communication errors that arise as we start hooking up communication code in later lessons. Make your new class support the three overloaded constructors that its base does. Add a read-write string property called Addressee, and a fourth constructor that accepts it as a parameter, along with message and innerException. (20 pts)

Note: The Microsoft web site somewhere contains a page saying something along the lines of, "We thought that separating system applications from application exceptions would be useful, but we found it wasn't, so we don't recommend that any more." I want to know the specific design advantages and disadvantages of your choice. Simply quoting a link will get you zero points for that part of this question. You must go through the thought process, and prove that you have gone through the thought process.

2. When the client calls SendAlert, add exception behavior as follows: If the addressee's name begins with the character 'A', then create a new SecureCommunicationException and throw it. If the addressee's name begins with the character 'B', then perform a division by zero and allow the resulting exception to propagate upwards to the client. If the addressee's name begins with 'C', then set up a try block and perform the division by zero. Catch the DivideByZeroException only. From within the catch block, create a new SecureCommunicationException with this as the inner exception, and throw the former. Allow all other calls to proceed without exceptions. (20 pts)

3. On the client side, add a try-catch block to your code that calls the object's method. Catch only the SecureCommunicationException at this level. Allow all others to propagate upwards. Pop up a message box to describe the exception you caught. (15 pts)

4. At the top level of the client application, catch all exceptions not otherwise handled, so as to shut down gracefully instead of blowing up in the user's face. Explain to the user what's happened. Make sure that you explain the situation properly to a non-programmer user, you will be graded on it. Offer a choice of whether or not to start a new instance of the program. Write the exception's data to a file (not the system event log) in lieu of sending an internet report. Hint: Make sure you test the client program outside the debugger as well as inside, the top-level exception behavior is different.  (35 pts)

5. Now that you've had some time to think about inheritance and its consequences, do the following: locate a CLR class provided by Microsoft, other than System.String, that is marked as 'sealed', meaning that you can't use it as a base class from which to derive another class. Argue carefully in a note to your TA, in 250 words or less, why you think Microsoft marked that class as sealed, and why you think that is a good decision or a bad one. Give a specific example supporting your contention. (15 points)