Introduction to Computing Using Python: An Application Development Focus by Ljubomir Perkovic

Introduction to Computing Using Python: An Application Development Focus by Ljubomir Perkovic

Author:Ljubomir Perkovic [Ljubomir Perkovic]
Language: eng
Format: epub, pdf
Tags: Python
Publisher: John Wiley & Sons
Published: 2011-12-19T16:00:00+00:00


Compare this to the execution shown in Figure 7.10, when the default exception handler handled the exception.

In the previous example, we chose to implement an exception handler at the point where function f(2) is called. This represents a design decision by the developer of function f() that it is up to the function user to worry about handling exceptions.

In the next example, the developer of function h makes the design decision that function h() should handle any exception that occur during its execution. In this example, the function h() is modified so that its code is inside a try block:

Module: stack2.py

1 def h(n): 2 try: 3 print(‘Start h’) 4 print(1/n) 5 print(n) 6 except: 7 print(‘Caught!’)



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.