Lesson 13: Exceptions Flashcards
What is error - checking code?
Code that a programmer introduces to detect and handle errors that occur while the program executes
What is the purpose of exception handling constructs?
They handle exceptional circumstances, or errors, during execution
What kind of code is placed in a “try” block?
Code that potentially may produce an exception.
When is an “except” block” used?
If the code in the try block causes an exception
What causes an unhandled exception to occur?
No exception handler existing for an error type
What does the interpreter do when it encounters an unhandled exception?
Print the exception that occurred and halt
When is a “raise” statement executed?
When code detects an error
What happens when a “raise” statement executes?
- Immediate exit from the try block and the execution of an exception handler
- The exception handler prints the argument passed by the raise statement that brought execution
What does the “as” keyword do?
Binds a name to the exception being handled
What does the “finally” clause in a try statement do?
Allows a programmer to specify clean - up actions that are always executed-