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 trial![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Daniel Liew Yew Onn](https://secure.gravatar.com/avatar/54bed28634b6878a19be32eafe7811de?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Daniel Liew Yew Onn
376 PointsHi there Can someone please help explain what Craig is trying to explain at 3:07 about the (as and err)?
except ValueError as err:
I dont not understand :(
3 Answers
![Chris Freeman](https://uploads.teamtreehouse.com/production/profile-photos/1153532/micro_image.jpg)
Chris Freeman
Treehouse Moderator 68,425 PointsHey Daniel Liew Yew Onn, good question. An except
statement handles specific errors that might arise during execution of the code following the try
. The raised exception is an instance that has attributes.
According to the docs:
The except clause may specify a variable after the exception name. The variable is bound to an exception instance with the arguments stored in instance.args.
So the as err
says "allow me to refer to the raised exception by the variable name err
". Using the err
reference, the exception attributes may be accessed. If the err
instance has a __str__
method defined, then a print(err)
will call that method and a string will be output.
Post back if you need more help. Good Luck!!
![Alok Yadav](https://secure.gravatar.com/avatar/4119c0ef2d3f08a9ef2e5b97f4a8d608?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Alok Yadav
1,023 PointsWhere is the err variable defined? If there are 2 types of errors in the code, how will it know which one the err is referring to?
![Chris Freeman](https://uploads.teamtreehouse.com/production/profile-photos/1153532/micro_image.jpg)
Chris Freeman
Treehouse Moderator 68,425 PointsWhile there are two possible places an error could be raised, but only one can be first. Whichever one is raised first is the error assigned to err
![Szymon Dabrowski](https://uploads.teamtreehouse.com/production/profile-photos/11651799/micro_IMG_0090.jpg)
Szymon Dabrowski
2,207 PointsChris Freeman, thank you kindly for this explanation. You have helped me out a ton!