sqyysec
class ShortInputException(Exception):
     \'\'\'你定义的异常类。\'\'\'
     def __init__(self, length, atleast):
        Exception.__init__(self)
        self.length = length
        self.atleast = atleast

try:
    s = raw_input(\'请输入 --> \')

    if len(s) < 3:
        # raise引发一个你定义的异常
        raise ShortInputException(len(s), 3)

except EOFError:
    print \'/n你输入了一个结束标记EOF\'
except ShortInputException, x:#x这个变量被绑定到了错误的实例
    print(\'ShortInputException: 输入的长度是 %d,长度至少应是 %d\'% (x.length, x.atleast))
else:
    print \'没有异常发生.\'

 

分类:

技术点:

相关文章:

  • 2021-12-27
  • 2021-09-22
  • 2022-01-02
  • 2021-11-06
  • 2023-03-24
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-09
  • 2022-01-19
  • 2022-01-25
  • 2021-12-23
  • 2021-11-30
相关资源
相似解决方案