In-Class Activity for Pair Programming (& Exception Handling) ------------------------------------------------------------- (courtesy of Ms. Coffman-Wolph, minor changes by Dr. Lilien) Skills/Goals of this activity: • Practice Windows Form Application programming • Practice using MessageBox • Practice exception handling (try/catch blocks) • Learn about user-defined exceptions • >>> Practice pair programming <<< ------------------------------------------------------ Create a small Windows Form application that does the following: After a user enters a number in the textbox and clicks the button, the program will check the value entered for two things: • Is it a number? • Is it a number in the 0-9 range? Requirements for Exceptions: ---------------------------- • Must use try/catch blocks for FormatException. • Must use a user-defined exception for making sure the number is in the 0-9 range. Steps: ------ 1) Create a form that contains a textbox and a button. 2) Create a class called TextboxFormatException that inherites from class Exception. 2a) Note: Class Exception already exists in C# so you do not need to create one. 2b) This class has no variables, but contains constructor(s). You should at least create a default constructor that calls the base constructor. • The base constructor will need 1 string parameter: this string should contain information regarding the error (for example: “Textbox format is incorrect. Must be a number 0-9”). 3. Add code to the form to do the following: 3a) Inside a try/catch block • Attempt to convert the information from the textbox into an integer. - You will need to catch a FormatException. - In the catch, you should clear the textbox and display a MessageBox that alerts the user that a formatting error has occured. • Check if the number is in the range of 0-9. - If the number is not inside this range, then you should clear the textbox and throw a TextboxRangeException. ====================================================================================