An exception should be
a) Used within a function
b) Thrown outside a try block
c) Listed in an exception specification for the function where the exception is thrown
d) Thrown in a different function than it is caught in. (If you select this, tell how are these functions related?)
e) Reserved for a situation where the way an exception should be handled depends on how and where the function is used
All parts except b) are correct.
It is impossible not to do as Part a) suggests. Remember that main() is a function. If you do as b) suggests, your program will terminate. Part c) is desirable since it provides a measure of error checking of your code. Part d) is typical of exception use. The function where the exception is caught calls the function where the exception is thrown. Part e) might be a situation where a library in use detects an error. It doesn’t know what to do, but throws an exception. The application knows what to do, and catches the exception and handles it.
You might also like to view...
Preview the presentation's animations to ensure that they have the intended effect
Indicate whether the statement is true or false
You can play and save movies and music in Vista using ________
Fill in the blank(s) with correct word