Python-异常

异常

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

你可能感兴趣的:(Python-异常)