2005-08-11

What to do about bare 'except's in Python

So my current PEP for tweaking exceptions for Python 3.0 has bare 'except's being the equivalent of ``except Exception``. A competing idea has been to do completely do away with bare 'except's. Which is better for the language?

The former is somewhat the more backwards-compatible solution. Since most existing code uses bare 'except's as if it should be ``except Exception`` most people should be able to leave their code and have things work the way they expect it to. But there will be issues with people who don't quite catch the subtle change and thus have non-obvious bugs.

Removing bare 'except's will break code. The change should be easy to do fix programmatically, though. It does remove something that some consider unPythonic thanks to the fact it will not be the only way to catch all exceptions (by virtue of having a required superclass) and thus enforce there being only way to do it. They also violate "explicit is better than implicit". Ripping out bare 'except's will make quick-and-dirty coding a little harder to do thanks it is more typing and requires a little bit more thought.

As of this moment my gut is saying to remove them since their usefulness will not be there anymore. Plus they do not go with Python dogma that well. They had their use when we had string exceptions and allowed any object to be raised, but that will no longer be here and thus their reason for existing will be gone.

No comments: