one more exception newbie query

P

Payal

Hi all,
In http://docs.python.org/tutorial/errors.html#handling-exceptions it
says,

| >>> try:
| ... raise Exception('spam', 'eggs')

Why would I want to use a class for exception? I could simply use raise
w/o it?
Also the help() says,
class Exception(BaseException)
But we have used 'spam' and 'eggs'. Why?

| ... except Exception as inst:

Now what does "as inst" do here? (Is it making an instance, but how?
Aren't instances made with this, inst = Klass() ?)

Thanks a lot in advance.
With warm regards,
-Payal
--
 
A

Alf P. Steinbach

* Payal, on 04.06.2010 12:10:
Hi all,
In http://docs.python.org/tutorial/errors.html#handling-exceptions it
says,

|>>> try:
| ... raise Exception('spam', 'eggs')

Why would I want to use a class for exception? I could simply use raise
w/o it?
Also the help() says,
class Exception(BaseException)
But we have used 'spam' and 'eggs'. Why?

| ... except Exception as inst:

Now what does "as inst" do here? (Is it making an instance, but how?
Aren't instances made with this, inst = Klass() ?)

These questions are like "why is the door rectangular when sheep are known to
dance in the moonlight only on dates divisible by cinnamon?".

It's rather difficult to answer.

I guess it's back to basics: read up on classes, instances, constructors.
Experiment, create a lot of small programs. Don't think about exceptions just
yet: you lack the fundamentals.


Cheers & hth.,

- Alf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,266
Messages
2,571,083
Members
48,773
Latest member
Kaybee

Latest Threads

Top