2022年4月6日 星期三

python exception strange with finally return will result no exception

 


def say():

    try:

        1/0

    except Exception as e:

        print("exception in side")

        raise Exception("say exception")

    finally:

        print("finally")

        # have this line happen no exception disappear

        return True

        

try:

    say()

except Exception as e:

    print("exception out side")

    print(e)



#>>>

exception in side

finally


#>>> no return statement is corrent

exception in side

finally

exception out side

say exception

沒有留言:

張貼留言