astropy/astropy — pull request #718 by astrofrog (2013-02-02 08:26:05+00:00)
Title: Fix to removing reference to caught exception

I ran into an issue in affiliated packages when the configuration file was not generated and the ``try...except`` block goes into the ``except`` block in ``__init__``, because on Python 3, the exception gets deleted at the end of the exception, so the explicit ``del e`` then fails. Here's a demo of the problem:

```
e = 1

try:
raise Exception()
except Exception as e:
print('raised exception')

del e
```

on Python 2:

```
raised exception
```

on Python 3:

```
raised exception
Traceback (most recent call last):
File "test_exception.py", line 8, in
del e
NameError: name 'e' is not defined
```

In practice, this will never normally happen in the core package because we can't import from the source tree in Python 3 because the code needs to be 2to3'd. But it's an issue in some affiliated packages, so for consistency we should fix it here. The solution is to move ``del e`` inside the ``try...except`` block.