Section 16.13. Exercises


16.13. Exercises



Exercise 16-1 .

Create a Cat class with one int property: Age . Write a program that creates a List of Cat objects in a try block. Create multiple catch statements to handle an ArgumentOutOfRangeException , and an unknown exception, and a finally block to simulate deallocating the Cat objects. Write test code to throw an exception that you will catch and handle.



Exercise 16-2 .

Modify Exercise 16-1 so that it does not throw an error. Create a custom error type CustomCatError that derives from System.Exception , and create a handler for it. Add a method to CatManager that checks the cat's age, and throws an error of type CustomCatError if the age is less than or equal to 0, with an appropriate message.



Learning C# 2005
Learning C# 2005: Get Started with C# 2.0 and .NET Programming (2nd Edition)
ISBN: 0596102097
EAN: 2147483647
Year: 2004
Pages: 250

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