CSE 1010 Lecture 21: CSE 1010 - Lecture 21 - Exceptions

47 views2 pages
Verified Note

Document Summary

A function should return a correct value or it should not return at all. This does not mean that a function should intentionally get stuck in an unbounded loop (thus, not returning) There should be some other means of exiting a function, something that is outside the normal path of execution. Example: def divide(x, y): if y != 0: return x / y. A correct value can be returned, otherwise, this function can"t return a correct value, so it shouldn"t return at all. An exception is a way to indicate that something unexpected happened, or something out of the ordinary. An exception is pretty much a fancy way to say that there"s an error. A function that raises an exception exits, but it does not return in the normal way you"re used to. This one is because there"s no colon after the parentheses. This one is because 2 is the largest index, not 3.

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