Study Notes (20): 21 days clearance Python (Video Lesson only) - Multi abnormal catch and exception handling and nested exception is thrown ...

Learning immediately: https://edu.csdn.net/course/play/24797/282200?utm_source=blogtoedu

# Raise an exception use
class Test47:

    @property
    def theAge(self):
        return self.__age

    @theAge.setter
    def theAge(self, age):
        if age > 30 or age < 10:
            # Raise # default RuntimeError
            # raise ValueError
            raise OSError (age, 'the age of input error')
        else:
            self.__age = age


# T47 = Test47 ()
# t47.theAge = 9

try:
    t47 = Test47 ()
    t47.theAge = 8
except OSError as e:
    print (e)
    print(e.errno)
    print(e.strerror)
    print(e.args)
Published 25 original articles · won praise 4 · Views 596

Guess you like

Origin blog.csdn.net/happyk213/article/details/105222840