week7discussion - Exceptions and Abstract Data Types...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Exceptions and Abstract Data Types
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Administrative Project 3 due Wednesday, Nov. 3 rd @ 11:59PM Start Early! Difficulty(P3) >> Difficultly(P2)
Background image of page 2
Exceptions why? Want to handle unusual conditions of your program at runtime Until now unusual conditions handled by REQUIRES clause, why is this method bad?
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Exceptions REQUIRES clause is just a comment on what the function requires, but doesn’t actually enforce it How do we write our functions to enforce the specifications of what they are supposed to do?
Background image of page 4
Exceptions Could try to re-write the function to handle all types of input by trying to modify the function to do things on unusual conditions This doesn’t work for the case of factorial, it’s undefined on negative values, so it shouldn’t do anything on those unusual inputs by definition Could use assert() whenever bad input is passed to a function, but this quits the program, which may not be the best thing to do
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Exceptions When an exception occurs, the normal block is exited, and another block, the handler, is used to handle the exception
Background image of page 6
Exceptions - Terminology Throwing an exception means the program has become aware that an exception has occurred Catching an exception is how the program responds to the exception once it has occurred Exceptions caused in a try block are handled in an associated, but separate catch block
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 22

week7discussion - Exceptions and Abstract Data Types...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online