<div>Hi,</div><div><br></div><div>I'm trying to get my head around the IronPython API by implementing a simple work-around for what I believe is a bug in the next() builtin,which I reported here: <a href="http://ironpython.codeplex.com/workitem/27383" target="_blank">http://ironpython.codeplex.com/workitem/27383</a>. This is my first look inside IronPython so this question, I assume, is pretty basic. How can I handle Python exceptions returned by TryInvokeUnaryOperator? I'm currently trying to do this to implement the default value argument in the next builtin.</div>
<div><br></div><div><div> public static object next(CodeContext/*!*/ context, object o) {</div><div> object value;</div><div> if (PythonTypeOps.TryInvokeUnaryOperator(context, o, "next", out value)) {</div>
<div> return value;</div><div> }</div><div> throw PythonOps.TypeError("{0} object is not an iterator.", PythonTypeOps.GetName(o));</div><div> }</div></div><div><br></div>
<div>
public static object next(CodeContext/*!*/ context, object o, object defaultVal) {</div><div> object value = next(context, o);</div><div> // This doesn't work.</div>
<div> if (value is StopIterationException) {</div><div> return defaultVal;</div><div> }</div><div> return value;</div><div> }</div><div><br></div><div>Thanks,</div><div>
Tristan</div>