title: Catching exceptions raised in imported modules
body: <p>I'm writing a Python program which uses the pyserial module. The program is designed to read the output from an Arduino module. I can open a serial object with:</p>
  
  <pre><code>ser = serial.Serial('/dev/cu.usbmodem641', 9600)
  </code></pre>
  
  <p>I can then read from it with:</p>
  
  <pre><code>line = ser.readline()
  </code></pre>
  
  <p>However, I want to be able to handle the exception that is thrown if I start the program without the Arduino module connected. The exception that is thrown is:</p>
  
  <pre><code>File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/serial/serialposix.py", line 292, in open
  raise SerialException(msg.errno, "could not open port %s: %s" % (self._port, msg))
  </code></pre>
  
  <p>If I try to catch this with a general <code>try/except</code> block in my main program, it isn't caught. I've tried importing the <code>SerialException</code> from <code>serialposix.py</code> but that doesn't work.</p>
  
  <p>Do I need to get my hands dirty with threading or is there another way of dealing with this? When the exception is thrown, I'd like to call    <code>time.sleep(5)</code> and then just retry until the connection is available.</p>