zoukankan      html  css  js  c++  java
  • 引发异常

    #!/usr/bin/python
    # Filename: raising.py


    class ShortInputException(Exception):
        '''A user-defined exception class.'''
        def __init__(self, length, atleast):
            Exception.__init__(self)
            self.length = length
            self.atleast = atleast


    try:
        s = 
    raw_input('Enter something --> ')
        if len(s) < 3:
            raise ShortInputException(
    len(s), 3)
        # Other work can continue as usual here
    except EOFError:
        print ' Why did you do an EOF on me?'
    except ShortInputException, x:
        print 'ShortInputException: The input was of length %d,
              was expecting at least %d' 
    % (x.length, x.atleast)
    else:
        print 'No exception was raised.'

  • 相关阅读:
    linux学习之路(2)
    Cocos.js
    BOM常用对象
    display取值和应用
    DOM
    cursor属性
    visibilty属性
    打开新连接的方式
    JQuery
    js的创建对象
  • 原文地址:https://www.cnblogs.com/nku-wangfeng/p/7696655.html
Copyright © 2011-2022 走看看