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

Python

What is a BaseException?

I keep getting this when I input a number over 100, what does it mean and what do I do with it?:

Traceback (most recent call last):
File "masterticket.py", line 13, in <module>
raise ("There are only {} tickets remaining".format(tickets_remaining))
TypeError: exceptions must derive from BaseException

    try:  
        prompt = int (input (" Hello {}.  How many tickets would you like?   ".format(user_name)))
        #rase error text in the output
        if prompt > tickets_remaining:
            raise ("There are only {} tickets remaining".format(tickets_remaining))
    except ValueError as err:
        print ("{}".format (err))

1 Answer

When you raise an exception you have to provide a type of exception, like ValueError, TypeError, etc and not just a pure string like you are doing in your code. BaseException is a class which all other exception types inherit from, it can be used to create custom exception types as well, but that is a more complex topic which you likely have not gotten to yet.

If you change your raise statement to something like this:

raise ValueError("There are only {} tickets remaining".format(tickets_remaining))

Then that error should go away.

Oh I just missed that. I forgot. Thanks!