<div>Instead of adding syntax, we could make except use isinstance.</div><div><br></div><div>This means that those people who are using exceptions with poor hierarchies can override the classes with their own. This makes for an ugly setup but a very readable result. If you put the class definitions in another file and import them, it may end up looking quite clean.</div>

<div><br></div><div>Please forgive me if I am doing this wrong, as I've never done this sort of thing before.</div><div><br></div><div><div><font face="courier new, monospace">class SpecificOSErrorType(type):</font></div>

<div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre">  </span>def __instancecheck__(cls, othercls):</font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre">               </span>if isinstance(othercls, OSError):</font></div>

<div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre">                  </span>if othercls.errno == self.errno:</font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre">                            </span>return True</font></div>

<div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre">          </span>return False</font></div><div><br></div><div><font face="courier new, monospace"><div>class FileExistsOSError(OSError, metaclass=SpecificOSErrorType):</div>

<div><span class="Apple-tab-span" style="white-space:pre">      </span>errno = 17</div><div><br></div><div><br></div><div>a = OSError(17, None)</div><div>b = OSError(10, None)</div><div>print(a.errno) # >> 17</div><div>
print(b.errno) # >> 10</div>
<div>print(isinstance(a, FileExistsOSError)) # >> True</div><div>print(isinstance(b, FileExistsOSError)) # >> False</div><div><br></div><div>try:</div><div><span class="Apple-tab-span" style="white-space:pre">     </span>raise FileExistsOSError</div>

<div>except OSError as e:</div><div><span class="Apple-tab-span" style="white-space:pre">   </span>print(e.errno) # >> 17</div><div><br></div><div>import os</div><div>try:</div><div><span class="Apple-tab-span" style="white-space:pre">     </span>os.mkdir("src")</div>

<div>except FileExistsOSError: # Fails</div><div><span class="Apple-tab-span" style="white-space:pre">      </span>print("Could not make directory: File already exists")</div><div><br></div></font></div></div><div><font face="arial, helvetica, sans-serif">Advantages:</font></div>

<div><font face="arial, helvetica, sans-serif">- No syntax change</font></div><div><font face="arial, helvetica, sans-serif">- Clean result (as would be expected if the hierarchy was right from the start)</font></div><div>

<font face="arial, helvetica, sans-serif">- Works with any library, and is backwards compatible</font></div><div><font face="arial, helvetica, sans-serif">- Would enable forward-compatibility (if this was in 3.2, we could re-implement the 3.3 hierarchy)</font></div>

<div><font face="arial, helvetica, sans-serif">- [Half-point] More general use of this may encourage better exception hierarchies</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">Disadvantages:</font></div>

<div><span style="font-family:arial,helvetica,sans-serif">- It doesn't work yet [*wink*]</span></div><div><font face="arial, helvetica, sans-serif">- It may be a bad idea to encourage people to override standard class hierarchies, even if we agree that they are badly designed in 3.2</font></div>

<div><font face="arial, helvetica, sans-serif">- Requires use of metaclasses and stuff people shouldn't need to understand</font></div><div><font face="arial, helvetica, sans-serif">- Setup is extremely ugly and much longer than the replaced code</font></div>