title: (OSError) Exception Handles (ConnectionRefusedError) Error
body: <p>I'm Trying To Catch Errors In Socket Connection With Python. I Need To Work With Two Different Types Of Errors <strong>[ ConnectionRefusedError, OSError ]</strong>. I Want To Perform A Different Action For Each Error, So I Did It With (try except) Statement, And When The Code Is Like The Shown Below <em>[Which (OSError) Exception Is Written First]</em>, Only The First Exception <em>[Which Is (OSError)]</em> Is Raised Even The Error Is (ConnectionRefusedError)<br>
  Code :    </p>
  
  <pre><code>for ip in ips:
      sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
      try :
          sock.connect((ip,12345))
          print("Up.")
          up.append(ip)
          sock.close()
      except OSError:
          print("Down.")
          raise
      except ConnectionRefusedError:
          print("Up.")
          up.append(ip)
      except Exception as e:
          print(e)
  </code></pre>
  
  <blockquote>
    <ul>
    <li>Output : Down.    </li>
    <li>Raised Error : ConnectionRefusedError: [Errno 111] Connection refused </li>
    </ul>
  </blockquote>
  
  <p>So The [OSError] Exception which has The <code>raise</code> Statement Raised [ConnectionRefusedError] (Which Is The Next Exception Statement !).</p>
  
  <p>. But When I Swap The Exceptions And Write (ConnectionRefusedError) First, It Works Fine:     </p>
  
  <pre><code>for ip in ips:
      sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
      try :
          sock.connect((ip,port))
          print("Up.")
          sock.close()
      except ConnectionRefusedError:
          print("Up.")
          up.append(ip)
      except OSError:
          print("Down.")
          raise
      except Exception as e:
          print(e)
  </code></pre>
  
  <p>So, Why OSError Exception Handles ConnectionRefusedError In The First Case ?
  And Is There A Way To Write OSError Exception First And It Works Immediately ?</p>