1

I want to create socket errors (By doing things, obviously) but I've no idea how I should test if my script handles errors properly (If it dectes them.)

Currently, my code is this:

except socket.error as err:
    print "Connection lost, waiting..."
    time.sleep(5)

In theory, it should handle all the socket errors, print and then sleep (It's a part of a while loop.).

Any idea of how can I test it to see how it handles errors?

0

1 Answer 1

1

Use the raise statement:

try:
    raise socket.error
except socket.error as err:
    print "Connection lost, waiting..."
    time.sleep(5)

Yet another example:

try:
    raise AttributeError
except AttributeError:
    print 'Sorry'
#Sorry

Also take a look at here and here

Sign up to request clarification or add additional context in comments.

2 Comments

Sorry for being late! I forgot to reply here. yes, DawG - I wasn't aware of this and it worked. It indeed returned what I wanted it! Thanks a lot.
Hah - Sorry. didn't mean to, I'd give 5000 points to everyone. I just plainly forget. Not that "I get the question" and I run, just forgot. Sorry.

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.