Get exception name in Python where it is not specific

Asked

Viewed 96 times

2

I’m using the exception Exception, but wanted to be more specific and take the correct exception, without the treatment the code returns me the following message:

F: Bel Desktop tpredes>guiCliente.py Exception in Tkinter callback Traceback (Most recent call last): File "C: Python27 lib lib-Tk Tkinter.py", line 1537, in call Return self.func(*args) File "F: Bel Desktop tpredes guiCliente.py", line 80, in upload self.test(True) File "F: Bel Desktop tpredes guiCliente.py", line 77, in test communication.send() File "F: Bel Desktop tpredes guiCliente.py", line 93, in send s. connect((self.ip,self.port)) File "C: Python27 lib socket.py", line 228, in meth Return getattr(self._Sock,name)(*args) error: [Errno 10061] No connection p to be made because the target machine refused them actively

I have tried several, but they do not work, I also researched on and did not find something specific, will be that the library that did not create exceptions different from the most general, Exception?

Thank you for your attention.

1 answer

1


It seems to me that it has to do with the connection. Try:

try:
   s.connect(('IP', 'PORT'))
except socket.error as exc:
   print 'Cautela: %s' % exc
  • Thank you very much, it worked right, could you explain? socket.error is probably pq searched in lib, but and the exc is a specific area? Thank you for your attention.

  • @Vinicius as is to give the name you want just that. Could be ... as YOO_MA_MEN: if I wanted to, and then: print 'Cautela: %s' % YOO_MA_MEN

Browser other questions tagged

You are not signed in. Login or sign up in order to post.