Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
Temi Folorunsho2,849 Points
Expecting and Raising exceptions
From the practice exercise i saw that i can have more than one exceptions in the try block but, instead of using the raise keyword we keep on using only except. Why?
Chris FreemanTreehouse Moderator 68,404 Points
raise is used to signal that your code found an error that needs handling and
try / except is used to handle an error that may arise from uncontrollable input from outside your code.
Sometimes you raise and handle an error within your own code. You might be tempted to simply handle the error without the try/raise/except structure. Using the try/raise/except structure helps define the code section as an error handling situation and adds readability.
Now to your question: It may be possible that more than one error may occur from calling exterior code. Stacking
except statements allows you to handle each type separately. Stacking
except statements to cover a block of your own code is sometimes used so you don’t have to wrap each line of the block in its own try/except statement.
Post back if you need more help. Good luck!!!