10.1
Throws an exception. Which of the following causes an exception to be thrown when the program executes? Note that we're not asking for exceptions here.
The reason.
a) users;
b) interpreter;
c) procedures;
D) all of the above;
(e) only B) and C);
f) only a) and C)
F
10-2. Throws an exception. Referring to the list of top issues, what factors throw an exception when the interaction interpreter is executed?
F
10-3. Keywords. What are the keywords that are used to throw exceptions?
Raise
10-4. Keywords. What's the difference between try-except and try-finally?
Try-except: When the try code block runs in error, the except code block will be executed (matching to the corresponding exception), after processing the exception after the Try-except code will continue to execute;
Try-finally: Eventually executes the code in finally, regardless of whether the try code block has an exception. If an exception occurs, the exception continues to be thrown at the top after the finally code block is executed.
i = 1try: = 10%iexcept: print('except ')try: = 10%ifinally: Print('finally')
Output: Finally
10-5. Exceptions. What exceptions will be thrown by the Python code snippet below these interaction interpreters (see the list of built-in exceptions given in Table 10.2):
(a) >>>if 3 < 4 Then:print ' 3 is less than 4! '
(b) >>>alist = [' Hello ', ' world ', ' anyone ', ' Home ']
>>>print ' The last string of alist is: ', Alist[len (alist)]
(c) >>>x
(d) >>>x = 4 0
(e) >>>import Math
>>>i = math.sqrt (-1)
(a) Syntaxerror:invalid syntax (b) indexerror:list index out of range (c) nameerror:name ' x ' are not defined (d) zerodivisi Onerror:integer division or modulo by zero (e) Valueerror:math domain error
10-6. Improved open (). Create a wrapper for the built-in open () function. Causes the file handle to be returned when the file is successfully opened: If Open fails, it is returned to the caller none, instead of generating an exception. This way you can open the file without the need for additional exception handling statements.
Python Core Programming Second Edition tenth Chapter after class answer