4a. Demonstrate an understanding of the roles of exceptions and exception handling in programming
Read the short framing texts for sections 4, 4.1.1, and 4.1.2 of the course. Section 8.1.2 of Eck's Introduction to Programming Using Java gives examples of error situations in programming involving arrays, pointers, memory leaks, and buffers that Java detects automatically, and, thus, can be handled as exceptions. What is a memory leak? Section 8.1.3 gives examples of errors that Java does not detect automatically.
In addition to the above data and computational errors there are application errors that pertain to satisfying the requirements of the program. If the requirements are not satisfied, the program is not correct, though it may run without being interrupted or having exceptions. Requirements related errors can be addressed by using preconditions, postconditions, and test statements. For reference, review Section 8.2 of Eck's Introduction to Programming Using Java.
4b. Demonstrate an understanding of how exceptions are handled in various programming languages, including C++ and Java
Java uses throws, try, and catch statements to handle exceptions. Part 1 of "Exceptions in the Java Programming Language" explained this approach. Part 2 explains the four classes of exceptions in Java. What are they? These classes include checked and unchecked exceptions. The former, checked exceptions, are those that are detected at compile time. The unchecked are detected are run time. Part 3 discusses the Error class, those exceptions that pertain to satisfying the requirements of the program. A custom exception class is defined by the programmer to handle the application errors. Section 8.3 of Eck's "Introduction to Programming Using Java" is a more thorough treatment of Java's throw-try-catch model. Does a catch block have to be in the same subroutine where the exception occurred? Understand the 'unwinding' of the call stack, which determines the order in which subroutines are searched for a catch statement for the exception.
The C++ approach to exceptions is similar to Java's and, also, uses the throws-try-catch model. Carefully examine the C++ throw-try-catch model described in "C++ Programming".
The inclusion of error and exception handling in a program is part of the design stage of the programming process. Java Error Handling outlines the design process steps for throwing and catching exceptions and gives examples of design decisions involving handling of exceptions. Any process effort involves a cost. Design and coding steps for handling exceptions trade off efficiency. In other words, a program that handles exceptions requires more space and more time to run. However, it will have higher quality with respect to correctness and robustness.
4c. Demonstrate an understanding of the differences as to how exceptions are handled in C++ and Java with regards to syntax
A careful reading of "C++ Programming" helps one deduce the following: all exceptions in C++ are unchecked, there is no 'finally' statement in C++, there is no 'throws' statement in C++, in C++ an exception can be of any type but in Java only of class throwable type, C++ has a catch all statement, namely catch (…).
Unit 4 Vocabulary
This vocabulary list includes terms that might help you with the review items above and some terms you should be familiar with to be successful in completing the final exam for the course.
Try to think of the reason why each term is included.