INFO1110 Lecture 6: 6 – Exceptions and file IO

93 views5 pages

Document Summary

Objects that signal the occurrence of an unusual event during the execution of a program. Exception mechanism: construct an exception object, throw/raise it, exception is caught or execution stops. Exception syntax in python: try a piece of code that may contain a rare exceptional error, exception is caught using except and handled except errorobject[ as identifier]: If error occurs, raise exception object (using an exception class created earlier: following the try, execute the block finally regardless if error occured. If an exception occurs in a method and it cannot be handled within the method then that method will terminate and throw the same exception to the caller of the method. The exception will be passed up until someone can handle it. When there are multiple except blocks to catch the exception, the first matching exception object will be executed. So except blocks should be ordered from most to least specific.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents