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
Mikaela Land
Python Web Development Techdegree Student 2,324 PointsRaising two ValueErrors?
Okay so I'm wondering if it's possible to raise two different ValueErrors in a function? If not what should I do? Below is the basics I'm having trouble with. If I have a separation with two functions instead how do you call two functions to combine my values?
def blah(name, age):
if type(name) != str
raise ValueError ("You need to enter your name.")
if age < 1:
raise ValueError ("You apparently aren't alive yet. try a differnt number
try:
your_name = input ("name here: ")
your_age = int(input ("Your age: "))
#below is where I'm having the most trouble
except ValueError as err:
print ("{}".format (err)
print ("{}".format (err)
print (blah (your_name, your_age))
1 Answer
Steven Parker
243,656 PointsWhen an exception is raised, the program will immediately jump to the appropriate "except" statement (or end, if there is none). Either way, the function itself is no longer running and does not have an opportunity to execute another "raise".
Also, in your example, you define the function "blah" but don't call it. So it won't raise any exception.