Thanks Jerry!<br><br>By the way, I know I can change the way the loops works and bypass this issue :)<br>I just wanted to mention this behavior which I thought interesting and present some corner case (I have worked extensively in testing). <br>

And I agree, probably I should not have used color. Bad on my part.<br><br>Cheers!!<br>Sumod<br><br><div class="gmail_quote">On Thu, May 3, 2012 at 7:48 PM, Jerry Hill <span dir="ltr">&lt;<a href="mailto:malaclypse2@gmail.com" target="_blank">malaclypse2@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Thu, May 3, 2012 at 9:57 AM,  &lt;<a href="mailto:spawgi@gmail.com">spawgi@gmail.com</a>&gt; wrote:<br>


&gt; Hello all,<br>
&gt;<br>
&gt; I have encountered the following scenario.<br>
&gt; Here is the code - on IDLE on Windows XP.<br>
&gt;<br>
&gt;&gt;&gt;&gt; while True:<br>
&gt;     try:<br>
&gt;         number = raw_input(&quot;enter number - &quot;)<br>
&gt;         print number * number<br>
&gt;     except ValueError:<br>
&gt;         print &quot;invalid number&quot;<br>
&gt;     except:<br>
&gt;         print &quot;unspecified exception&quot;<br>
&gt;     else:<br>
&gt;         print &quot;other conditions&quot;<br>
&gt;<br>
&gt;<br>
&gt; enter number - 3<br>
&gt; unspecified exception<br>
&gt;<br>
&gt; What I noticed is that no matter, what input I give, I cannot exit this<br>
&gt; loop. I have tried control-C, control-D etc. all the keys. So how can I exit<br>
&gt; from this loop?<br>
<br>
</div>You can&#39;t, because you&#39;ve painted yourself into a corner.  The bare<br>
&quot;except:&quot; line will catch any exception at all.  Including the<br>
KeyboardInterrupt exception that is raised when you hit control-c.  If<br>
you must catch unknown exceptions, but still want to allow the<br>
KeyboardInterrupt exception from pressing control-c to exit your<br>
program, then use &quot;except Exception:&quot;<br>
 instead of a bare &quot;except:&quot; statement.  Since KeyboardInterrupt (and<br>
SystemExit) are not subclasses of Exception, they won&#39;t be caught.<br>
<br>
KeyboardInterrupt and SystemExit are subclasses of a class called<br>
BaseException, instead of Exception, for this exact purpose.  See more<br>
about python&#39;s exception hierarchy here:<br>
<a href="http://docs.python.org/library/exceptions.html" target="_blank">http://docs.python.org/library/exceptions.html</a><br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Jerry<br>
</font></span><div class="HOEnZb"><div class="h5">_______________________________________________<br>
Tutor maillist  -  <a href="mailto:Tutor@python.org">Tutor@python.org</a><br>
To unsubscribe or change subscription options:<br>
<a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><a href="http://spawgi.wordpress.com" target="_blank">http://spawgi.wordpress.com</a><br>We can do it and do it better.<br>