raise or not to raise [Newbie]

Paddy paddy3118 at netscape.net
Sat Feb 3 16:21:00 EST 2007


On Feb 3, 9:07 pm, Jacol <jgrzeb... at NO.gazeta.pl.SPAM> wrote:
> I understand that author generated exception and than extracted the name of
> function from the exeption. But is any sens in using exeptions service if
> we have smthing simpler: just print for example? In my opinion no, it
> doesn't make sens.
>
> Jacek

You can terminate your program by raising an exception that you don't
otherwise catch and handle. e.g:

>>> def with_error():
... 	print "Print this then raise an error"
... 	raise Exception("Bye Bye")
...
>>>
>>> with_error()
Print this then raise an error
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
  File "<interactive input>", line 3, in with_error
Exception: Bye Bye
>>>

Notice how the traceback, automatically added to un-caught exceptions,
shows were it was raised.

Your link points to a very old version of Python and error handling
has changed. Please use a more recent tutorial such as THE Python
tutorial here:
  http://docs.python.org/tut/node10.html

- Paddy.




More information about the Python-list mailing list