技术博客Python

Python-异常

2018-01-10  本文已影响0人  老生住长亭

异常

1、结构:

try:

except:

else: // 没有异常时执行

finally:

2、创建异常

异常什么都不做

class DemoException(Exception):pass

抛出点异常

class ExceptionTest:

    def faulty(self):

        raise Exception("Her is something wrong")

    def ignore_exception(self):

        self.faulty()

    def handle_exception(self):

        try:

            self.faulty()

        except:

            # print("Handler Exception")

            raise

        else:

            print("handler exception don handler")

3、异常对象捕捉

raise

上一篇 下一篇

猜你喜欢

热点阅读