Welcome to the Treehouse Community
Looking to learn something new?
What is 'raise' exactly, and what does it do?
I don't think I completely understand what raise is for and how it's used. If except can handle common errors very well, doesn't that make the use of raise redundant inside of a try-except block?
try: print( 5/0 ) except ZeroDivisionError: raise ValueError("An error occurred!")
What's the difference if we handle it this way:
try: print( 5/0 ) except (ZeroDivisionError, ValueError): print("An error occurred!")
I searched the web for a good explanation of what raise does and I couldn't find one that is not confusing. Could anyone please break this for me in simple English? Thank you.
Steven Parker216,165 Points
Print just causes a message to appear, raise creates an error condition.
The message associated with raise is secondary to the primary purpose of creating the error condition. Unless the program handles that condition (with another except), the program will stop running.