2014年9月13日土曜日

開発環境

Learning Python (Mark Lutz (著)、Oreilly & Associates Inc)のPART Ⅲ.(Statements and Syntax)、Chapter 10.(Introducing Python Statements)、Test Your Knowledge: Quiz 7.を解いてみる。

その他参考書籍

Test Your Knowledge: Quiz 7.

コード(BBEdit)

sample7.py

#!/usr/bin/env python3
#-*- coding: utf-8 -*-

# a try statement is for catching exceptions.

import sys

try:
    a = 1 / 0
except Exception as err:
    print(type(err), err)
    print(sys.exc_info())

try:
    a = 'k' + 1
except Exception as err:
    print(type(err), err)
    print(sys.exc_info())

入出力結果(Terminal, IPython)

$ ./sample7.py
<class 'ZeroDivisionError'> division by zero
(<class 'ZeroDivisionError'>, ZeroDivisionError('division by zero',), <traceback object at 0x109220748>)
<class 'TypeError'> Can't convert 'int' object to str implicitly
(<class 'TypeError'>, TypeError("Can't convert 'int' object to str implicitly",), <traceback object at 0x109220748>)
$

0 コメント:

コメントを投稿