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! While you're at it, check out some resources Treehouse students have shared here.
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 trialeestsaid
1,311 PointsUnsure how the "raise" function works
At about 1:30 Craig describes how the "raise" function works and goes on to describe error handling. I'm finding it hard to follow what he is describing. If someone could try explaining it that would be super helpful.
Thanks team.
2 Answers
Chris Freeman
Treehouse Moderator 68,457 PointsLetβs start by defining a exception as an error while running a program. (See list of built-in Exceptions). These can be as simple as a SyntaxError
, or a KeyError
when looking up something in a dict
. Each error type is given the unique name so that the programmer may choose to resolve the error with in the program. Any error not handled in the program will be passed to the operating system to handle. At this point the program usually halts.
Sometimes a programmer wants to trigger a specific error. The mechanism a programmer uses is called raising an error and is done using the raise
function.
More information is available in the docs errors.
Post back if you need more help. Good luck!!!
eestsaid
1,311 PointsThanks Chris - your explanation simplified the content and the docs helped pad out my understanding.