exception

‘docs.python.org’ about ‘exception’
在這裏插入圖片描述


def exception_example():
    a = 0
    try:
        a = 1/0
    except Exception as e:
        print(e)
    else:
        a = 1
    finally:
        print(a)


class MyException(Exception):
    pass


def my_exception_example():
    my_exception = MyException("my exception!")
    try:
        raise my_exception
    except Exception as e:
        print(e)
    else:
        print("no exception.")
    finally:
        print("exception process end")


if __name__ == '__main__':
    exception_example()
    my_exception_example()

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章