[Python-ideas] Use `isinstance` check during exception handling
Random832
random832 at fastmail.com
Thu Nov 5 10:45:32 EST 2015
Michael Selik <mike at selik.org> writes:
> After reading https://github.com/sjoerdjob/exhacktion/ I have a better
> understanding of what you want to accomplish. However, I'm still not
> clear on where the pain is coming from. If you find yourself writing
> an if in an except many times as you described:
>
> try:
> os.chown("README.md", 100, 100)
> except EnvironmentError as e:
> if e.errno == errno.ENOENT:
> pass
> else:
> raise
You know, it occurs to me, there are some languages that support this as
a high-level feature. I.e. in Visual Basic
Try
[Statements]
Catch ex As Exception When [Boolean-valued expression]
[Statements]
End Try
This is in fact the *only* way that MS Windows "Structured Exception
Handling" exceptions work in C:
__try { ... }
__except([BOOL-valued expression]) { ... }
Both of these have the effect that the exception "was never caught" if
it returns false.
More information about the Python-ideas
mailing list