How to sell Python to your boss?

Greg Ewing greg.ewing at compaq.com
Tue Aug 31 18:56:59 EDT 1999


Diego Dainese wrote:
> 
> Sorry for the OT, but why is it better to not use the C++ exceptions?

Exceptions in C++ don't seem to be as convenient as they
are in Python. You can't just drop everything on the floor
and bail out on an exception, lest you leak memory, so you
have to think all the time about what will happen if an
exception occurs in the middle of what you're doing.

There's no equivalent of "finally", which makes it awkward
to write cleanup code which gets done whether there is an
exception or not. You can do it with destructors, but that's
not always convenient, e.g. in

  Blarg *temp_b = new Blarg();
  ...something which might throw an exception...
  delete temp_b;

nothing is going to destroy temp_b if there is an exception.
There are various ways to solve that, but all of them require
extra work, allow room for error, and none are as elegant as 
Python's "finally".

Also, when you catch an exception you have to catch a
particular type of exception. And there's no language-enforced
superclass for all exceptions. This makes it hard to put a
general catch-all handler at the top of your application
without knowing all the possible exceptions which could
occur in your code and any libraries you use.

So, all round, I wouldn't blame anyone for deciding that
C++ exceptions are more trouble than they're worth.

Greg




More information about the Python-list mailing list