[Twisted-Python] trouble with missing exceptions

Andrew Bennetts andrew-twisted at puzzling.org
Wed Oct 10 19:37:36 EDT 2007

markus espenhain wrote:
> hi
> i've written a tcp client - using a derived NetstringReceiver, a 
> ReconnectingClientFactory and just reactor.connectTCP + reactor.run.
> the problem is that after the connection is made - every exception that 
> occurred seems to be lost and the execution at this point discontinues - 
> also with a try/catch block around it
> class MyProtocol(basic.NetstringReceiver):
> 	...
> 	def onData(self, data):
> 		print data
> 		try:
> 			print 'before' # printed
> 			raise Exception('err')
> 		except Exception, e:
> 			print e # nothing
> 		print 'after' # nothing
> after print 'before' nothing more in onData happens - anyway the app 
> runs and on new data the onData is entered again
> i poke around 2h or so and i can't remember to had this problem before 
> ... so anybody can give me a hint or maybe something that i miss?

I'm guessing this isn't literally code you've tried to run, because that will
always print e and 'after'.  There's nothing in Twisted that changes the way
Python's exception handling works.

Taking a guess that by “raise Exception('err')” you mean you call a function
that somehow raises an exception your “except Exception:” block fails to catch,
perhaps try a bare “except:”.  It might be a string exception.

Otherwise, I'd try making as minimal an example of the problem as you can that
can reproduce the problem, and if you're still stuck, posting that to this list
(or if it doesn't involve Twisted, comp.lang.python).  Or use “import pdb;
pdb.set_trace()” to insert a breakpoint and step through the code in the


More information about the Twisted-Python mailing list