On Jan 18, 2008 4:23 PM, Brad Smith &lt;<a href="mailto:bnsmith@gmail.com">bnsmith@gmail.com</a>&gt; wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Suppose that an exception is thrown in lineReceived or<br>rawDataReceived, maybe just something as simple as a naming error<br>caused by a misspelled variable name. Is there any way to implement a<br>default exception handler that would allow me to send something back
<br>to the client before the protocol dies? It would be nice to send the<br>exception traceback to the client to help figure out what went wrong.<br>I suppose I could wrap all of the methods in the class in a try/catch<br>
block, but that would be a lot of wrapping to do. I&#39;d prefer to be<br>able to do something like adding a &#39;defaultExceptionHandler&#39; method to<br>the LineReceiver derived class that would be called by the reactor.
<br></blockquote><div><br>It will save you more time to fix such a critical bug as a naming error rather than build a protocol to only tell the client the server is broken.&nbsp; However to answer your question, no.<br><br>Remember from the Zen of Python: &quot;explicit is better than implicit&quot; so to handle legitimate errors you should define what exceptions are likely to occur and incorporate these in your protocol design for error feedback to the client.&nbsp; If you want some kill-all exception handler for all your protocols, consider writing a decorator:
<br><br>@sendTraceback<br>def lineReceived(self, line):<br>&nbsp;&nbsp;&nbsp; pass # do stuff<br><br></div></div><br>-- <br>\\\\\/\&quot;/\\\\\\\\\\\<br>\\\\/ // //\/\\\\\\\<br>\\\/ &nbsp;\\// /\ \/\\\\<br>\\/ /\/ / /\/ /\ \\\<br>\/ / /\/ /\ &nbsp;/\\\ \\
<br>/ /\\\ &nbsp;/\\\ \\\\\/\<br>\/\\\\\/\\\\\/\\\\\\<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; d.p.s