Python: Catch exception and repeat code
<p>I have this code:</p>

<pre><code>import imaplib, re
import os
import time

conn = imaplib.IMAP4_SSL("imap.gmail.com", 993)
conn.login("ddd", "dddd")

while(True):
        unreadCount = re.search("UNSEEN (\d+)", conn.status("INBOX", "(UNSEEN)")[1][0]).group(1)
        print unreadCount

        if int(unreadCount) &gt; 10:
                print "restarting..."

        time.sleep(50)
</code></pre>

<p>Which sometimes loses the connection and stops working. How can I catch the exception and start the code over every time it breaks?</p>

<p>Thanks</p>
