Handling non-local errors at runtime (part 1)
On this page
Handling non-local errors at runtime
Exceptions
Errata: On the slide titled Exceptions we write that the catch-block is followed
by an exception handler. We meant to write that the try block is followed by an exception handler that
specifies the types of objects that it can catch.
Questions
Q1
QExceptions, Q1
This question is ungraded.
You should write code that might throw an exception that you'd like to handle under a
block.
Q2
QExceptions, Q2
This question is ungraded.
Exception handlers are introduced after the try-block using the keyword
.
Q3
QExceptions, Q3
This question is ungraded.
Given,
double AreaRectangle(double width, double height) {
double area = width * height;
if (area < 0)
// do something
return area;
}
best practice dictates that line-4 should:
Q4
QExceptions, Q4
This question is ungraded.
If an exception is thrown, but is not caught, then
Q5
QExceptions, Q5
This question is ungraded.
True or false: best practice suggests that we should use exceptions to handle not only non-local errors, but local errors too!