473,322 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

How to catch error

75
I have this one code, where I have to catch a specific error code. (I'm using win xp)

data = connection.recv(8048)

without any error catching, I get error message:
"error: (10035, "The socket operation could not complete without blocking")
I need to identify this error message 10035 in my code but dont know how to do it.

I tried:

Expand|Select|Wrap|Line Numbers
  1. try:
  2.    data = connection.recv(8048)
  3. except (error):
  4.    print error
  5.  
it now prints <class 'socket error'> , and I want it to print that 10035error (and then handle it ofcourse)

I get somewhere the following code, but this doesn't work either:

Expand|Select|Wrap|Line Numbers
  1. import errno
  2. ...
  3.  
  4. try:
  5.    data = connection.recv(8048)
  6. except, (error,message):
  7.    print error
  8.    if error == errno.WSAEWOULDBLOCK:
  9.       print "10035 error found, doing something..."
  10.  
I don't understand that "," mark after the except, so the code gives me syntax error right away because of that... but in the code the error message should be a tuplet which I save to these variables and then see if the error code matches errno.WSAEWOULDBLOCK (that's the (windows) error 10035)

could anyone help me? =)
Nov 28 '07 #1
5 10435
dazzler
75
argh, I already found out the solution ;-D

it should be:
except Exception, (error, message):
not:
except, (error, message):

well, maybe this message will help someone else too who's having problems catching specific error codes...
Nov 28 '07 #2
dazzler
75
argh, I already found out the solution ;-D
well, it isn't working so well after all =D

because there is also other error which must be caught

except Exception, (error, message):
handles all exception, I want it to handle only this "10035 error" because when there happends other exception (socket timeout) I got this error:
....
Traceback (most recent call last):
....
except Exception, (error, message):
ValueError: need more than 1 value to unpack

so the expection is wrongly formatted to this other expection, uhm =(
Nov 28 '07 #3
dazzler
75
Expand|Select|Wrap|Line Numbers
  1. try:
  2.    connection, address = s.accept()
  3.    data = connection.recv(8048)
  4. except socket.error:
  5.  
this doesn't work, I get:
"AttributeError: '_socketobject' object has no attribute 'error' "

there is socket.timeout exception in socket module but I don't know how to use it =/
Nov 28 '07 #4
dazzler
75
ok, I solved this, but I think that there's also better solution, I dont want to compare that "timed out" string ;)

Expand|Select|Wrap|Line Numbers
  1. try:
  2.    connection, address = s.accept()
  3.    data = connection.recv(8048)
  4.  
  5. except Exception, errorcode:
  6.    if errorcode[0] == "timed out":
  7.       print "time out, doing something..."
  8.    elif errorcode[0] == 10035:
  9.       print "error 10035, doing something..."
  10.  
Nov 28 '07 #5
Expand|Select|Wrap|Line Numbers
  1. try:
  2.    connection, address = s.accept()
  3.    data = connection.recv(8048)
  4.  
  5. except socket.timeout:
  6.    print "time out, doing something..."
  7. except Exception, errorcode:
  8.    if errorcode[0] == 10035:
  9.       print "error 10035, doing something..."
I don't know if that will help you any, posting two months later, but that should be how to handle multiple exceptions.
Jan 17 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: kaeli | last post by:
Hey all, I'd like to start using the try/catch construct in some scripts. Older browsers don't support this. What's the best way to test for support for this construct so it doesn't kill...
7
by: Arjen | last post by:
Hi, I'm doing this: try { try { } catch(Exception ex){ throw;
23
by: VB Programmer | last post by:
Variable scope doesn't make sense to me when it comes to Try Catch Finally. Example: In order to close/dispose a db connection you have to dim the connection outside of the Try Catch Finally...
3
by: will | last post by:
Hi all. I've got an question about how to catch an exception. In Page_Load, I place a DataGrid, dg1, into edit mode. This will call the method called GenericGridEvent. GenericGridEvent will call...
32
by: cj | last post by:
Another wish of mine. I wish there was a way in the Try Catch structure to say if there wasn't an error to do something. Like an else statement. Try Catch Else Finally. Also because I...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.