On Jan 18, 2008 4:23 PM, Brad Smith <<a href="mailto:bnsmith@gmail.com">bnsmith@gmail.com</a>> 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'd prefer to be<br>able to do something like adding a 'defaultExceptionHandler' 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. However to answer your question, no.<br><br>Remember from the Zen of Python: "explicit is better than implicit" 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. 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> pass # do stuff<br><br></div></div><br>-- <br>\\\\\/\"/\\\\\\\\\\\<br>\\\\/ // //\/\\\\\\\<br>\\\/ \\// /\ \/\\\\<br>\\/ /\/ / /\/ /\ \\\<br>\/ / /\/ /\ /\\\ \\
<br>/ /\\\ /\\\ \\\\\/\<br>\/\\\\\/\\\\\/\\\\\\<br> d.p.s