CST1801 Visual
Basic I
Lab Week 8
Example of using a
try-catch block Sample Code Result (Save to your local machine and run) |
Exercises |
Exercise
RationalExceptions (10 points)
In this exercise your are going to build upon Exercise RationalCalculations that you completed last week. By nature of the working with rationals, there definitely is the possibility of a divide by zero error and also errors from parsing non numeric input from the input text boxes. Modify your program using try - catch - finally exception handling to handle all possible errors. Make your program bulletproof so that it can handle all input possibilities. General programming philosophies are that methods in classes are not to have any direct interaction with the user GUI. In other words, there should be no error pop up message boxes generated within the classes that you wrote. However the error handling can be preprocessed in the class methods, and then throw a new Exception with a custom error message. Write a catch block in the main Windows GUI program to actually catch the custom exceptions and display of the custom error messages and then take corrective action. Write a main Windows GUI program (RationalExceptions) to test your classes and error handling. Result (Save to your local machine and run) Note: |
Exercise 17.3
TriangleArea (10 points)
If you know the length of the three sides of a triangle, the area can be calculated by:
where
Write method for calculating and returning the area. Make it throw a suitable exception (with a message) when the three lengths cannot form a triangle. Catch input formatting errors in the main program. Write a main Windows GUI program (Ex17_3) that catches the exceptions and takes appropriate action.
Result
(Save to your local machine and run) |