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 trialAlexandra Wakefield
Courses Plus Student 382 Pointserr is calling class, but is not finding raise within the function
While using err
allowed me to clean up the error message within the console, it is not grabbing the message prompted after raise
within the function. Instead, it only calls <class 'ValueError'>
and similarly with ZeroDivisionError. What is preventing the message from showing and how do I unblock this prevention?
def splitCheck(totalAmount, totalCustomers):
amountDue = round(totalAmount / totalCustomers, 2)
if totalAmount <= 0:
raise ValueError("Remember: Insert the number needing to be paid.")
if totalCustomers <= 1:
raise ValueError or ZeroDivisionError("Remember: You need more than 1 person to split a check.")
print("Each person will pay ${}.".format(amountDue))
try:
totalAmount = float(input("How much is the check? "))
totalCustomers = int(input("How many people are paying? "))
splitCheck(totalAmount, totalCustomers)
except ValueError or ZeroDivisionError as err:
print("Oh no! That didn't look like a valid number.\nPlease, try again.")
print("{}".format(err))
Thanks, in advance.
1 Answer
Steven Parker
231,268 PointsI'm not sure what you were intending the "or" to do, but it will return the first operand that is not "falsey" (so in this case, ValueError — with no message).
You have a similar issue with the except, but there you can catch multiple exceptions by using a tuple:
except (ValueError, ZeroDivisionError) as err: