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)
![Aassem Hadiouche](https://secure.gravatar.com/avatar/af39d769b4dbcb140a69f11509ed2a89?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Aassem Hadiouche
6,570 PointsQuestion about logic of "as err"
When Craig is explaining how to get the ValueError message from the function, he says to change the "except ValueError:" code to "except ValueError as err:" and then he also needs to print a message with ".format(err)" to get the original message from the function.
It's not clicking for me how python knows to refer to the "raise ValueError" in the function when you are in the try block of code.
Do you have to use the keyword "err" in this case?
What does "as" do so that the compiler knows to refer back the "raise ValueError" in the function?
I imagine there's some detail I'm forgetting that puts all the pieces together but it's not coming to me. Thanks in advance for any and all help!
2 Answers
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 PointsThe "except" by itself responds to the ValueError.
What the "as" does is save the error object where you can get to it in the handler code. The term after "as" is the name of the variable where you want it to be saved (in this case, "err").
![ChiaChi Chang](https://secure.gravatar.com/avatar/ca9efffcc2b39a64e72041a36dd81330?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
ChiaChi Chang
273 Pointsunderstood about the "as" is creating a variables
but how compiler knows the variable after "as" ("err" in this case) refer back the "raise ValueError" in the function? I thought it could be showed the result of "except" again
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 PointsThe systems puts an object containing data about the exception into the variable when the exception happens. In this case, it is caused by the "raise" statement.
Zahkyi Ferguson
504 PointsZahkyi Ferguson
504 PointsThank you for your explanation. So "as" essentially creates variables for error objects, what kind of value is "as"?
Steven Parker
230,688 PointsSteven Parker
230,688 PointsIt's an operational keyword, like "except".