[Python-ideas] PEP-3151 pattern-matching

Antoine Pitrou solipsis at pitrou.net
Thu Apr 7 11:17:16 CEST 2011


On Thu, 07 Apr 2011 10:43:25 +0200
"M.-A. Lemburg" <mal at egenix.com> wrote:
> 
> It would be even more useful, if there were a way to catch
> standard IOErrors with those errnos using those same classes,
> so that the following becomes possible:
> 
> try:
>  ...
>  raise IOError(errno.EPERM, "permission denied")
> except PermissionError:
>  ...
> 
> and works as one would expect, that is, catch the EPERM error.

> Perhaps the IOError constructor could be made to switch
> the class of the generated object based on the errno
> attribute passed to the constructor.

Nice suggestion. I'll try to see if that is possible.

Regards

Antoine.





More information about the Python-ideas mailing list