Extension types as exceptions

M.-A. Lemburg mal at lemburg.com
Thu Aug 12 21:06:14 CEST 1999


Daniel Dittmar wrote:
> 
> Should it be possible to use extension types (implemented in C) as
> exceptions?

Good question. Even though it makes more sense to subclass the
ones in exceptions.py (this is possible from within C too) and
then include any additional information in the parameters, it should
basically be possible to "raise" any object as exception just like
in C++.
 
> Currently, this works partly, as you can 'raise' and 'except' them.
> It doesn't work in the following code:
> 
> try:
>     ... code raising exception
> except EOFException, err:
>     pass

The code you show here doesn't have anything to do with this. The
functionality would have to be added to Python/errors.c and ceval.c
(plus maybe other files).
 
> When the exception doesn't match any 'except' clause, it seems to be
> reraised through the following code in ceval.c:
> 
>                 case END_FINALLY:
> ...
> 
> Only strings and python classes seem to be allowed.

Strings, classes and instances are allowed.

Hope that helps.
-- 
Marc-Andre Lemburg
______________________________________________________________________
Y2000:                                                   141 days left
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/





More information about the Python-list mailing list