+ 1
Raise Exception, Rest Still Runs
This code from a lesson runs fine. try: print("Hello") print(1 / 0) except ZeroDivisionError: print("Divided by zero") # this is where it should stop and the following line should not run, but it does print("This code will run no matter what") I deletes "finally" and made the print() line it's own code... everything runs. Why doesn't the program stop running after an exception is called?
5 Answers
+ 18
I believe this is what we call exception handling in Python (?). The exception is caught, the process for that block is terminated and a corresponding prompt is sent to console output. Exception handling enables the program to continue to function without crashing.
+ 3
Oh okay. wow even if this IS simple it's still a lot to take in.
+ 3
Exceptions aren't crashes. It just means that if A doesn't work, do B.
+ 1
I believe the print is executed due to Indentation factor. It is in same line as try and except blocks defined.
+ 1
yes, but the last line containing "print" was a "finally" block. i erased "finally" and made print it's own line. i was wondering why it didn't stop at the error.