On Thu, Dec 31, 2009 at 12:18 PM, Phlip <span dir="ltr"><<a href="mailto:phlip2005@gmail.com">phlip2005@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
The point is I need to augment that layer's exceptions with extra<br>
information that I know about that layer.<br>
<br></blockquote><div><br></div><div>I would take advantage of the fact that exceptions are real, full-blown objects, and not just treat them as something that holds a string.</div><div><br></div><div>Meaning:</div><div>
<br></div><div>class DeepException(Exception):</div><div> pass</div><div><br></div><div>class ShallowException(DeepException): # you may or may not really want to inherit from DeepException</div><div> def __init__(self, deep_exception, more_information):</div>
<div> self.message = more_information</div><div> self.deep_exception = deep_exception</div><div><br></div><div>try:</div><div> deep_arcane_layer()</div><div>except DeepException d:</div><div> raise ShallowException(d, "Some other information")</div>
<div><br></div><div>Then if someone catches ShallowException, they can check out the 'message' attribute (which could have come from the DeepException, or "Some Other Information", and contain whatever information this higher layer knows in however many attributes/messages). If they want to get at the original exception, its available as an attribute, with all of the information that it had.</div>
<div><br></div><div>HTH,</div><div><br></div></div><div name="mailplane_signature">--S</div>