码迷,mamicode.com
首页 > 编程语言 > 详细

python自定义异常

时间:2019-11-07 20:49:50      阅读:103      评论:0      收藏:0      [点我收藏+]

标签:exception   input   自定义   pytho   print   pre   tin   cep   ini   

class ShortInputException(Exception):
    def __init__(self, msg):
        self.msg = msg
 
    def __str__(self):
        return str(self.msg)
    
 
try:
    print(‘zz‘)
    raise ShortInputException(‘短了。。。‘)
except Exception as e:
    print(e)

 代码如上所示:

python自定义异常

标签:exception   input   自定义   pytho   print   pre   tin   cep   ini   

原文地址:https://www.cnblogs.com/linwenbin/p/11815426.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!