carl
carl

Reputation: 4426

how to handle exceptions in python

I get errors like this

return SegmentWriter(self, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/whoosh/writing.py", line 502, in __init__
    raise LockError
whoosh.index.LockError

I would like to catch these errors with a try/except statement. So I wrote

try:
    do whatever causes the error
except LockError:
    print "LockError..."
    handle error

but this leads to a NameError, since LockError is unknown?

    except LockError:
NameError: global name 'LockError' is not defined

how do I handle these Lock errors?

Upvotes: 0

Views: 232

Answers (1)

Daniil Ryzhkov
Daniil Ryzhkov

Reputation: 7596

First import exception in your namespace. Add this to your module:

from whoosh.index import LockError

Upvotes: 4

Related Questions