473,233 Members | 1,543 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,233 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 10430
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
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...

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.