0

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?

5
  • 1
    Have you tried except whoosh.index.LockError:? Commented May 23, 2016 at 8:51
  • u can try except Exception as e: in the next line print e Commented May 23, 2016 at 8:53
  • @manojprashantk please don't suggest things like that. It's a terrible idea to catch all exceptions; only ever catch the ones you are expecting and know how to deal with. Commented May 23, 2016 at 9:11
  • @DanielRoseman: I think they meant to help with debugging; catch all exceptions just to be able to see the type. Commented May 23, 2016 at 9:11
  • @Daniel Roseman thanks for your suggestion. But that is why i have given it as a comment rather than posting it as an answer :) Commented May 23, 2016 at 9:56

1 Answer 1

4

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

from whoosh.index import LockError
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.