Created
December 12, 2011 15:52
-
-
Save dketov/1467982 to your computer and use it in GitHub Desktop.
Классы исключений
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
""" | |
Деление на ноль | |
""" | |
try: 1/0 | |
except ZeroDivisionError: | |
print "caught divide-by-0 attempt" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
""" | |
Ошибка использования типа | |
""" | |
value = "2" | |
print repr(value), "is ", | |
try: | |
value + 0 | |
except TypeError: | |
# not a number, maybe a string, Unicode, UserString...? | |
try: | |
value + '' | |
except TypeError: | |
print "neither a number nor a string" | |
else: | |
print "a string or string-like value" | |
else: | |
print "a number of some kind" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
""" | |
Иерархия встроенных исключений | |
BaseException | |
+-- SystemExit | |
+-- KeyboardInterrupt | |
+-- GeneratorExit | |
+-- Exception | |
+-- StopIteration | |
+-- StandardError | |
| +-- BufferError | |
| +-- ArithmeticError | |
| | +-- FloatingPointError | |
| | +-- OverflowError | |
| | +-- ZeroDivisionError | |
| +-- AssertionError | |
| +-- AttributeError | |
| +-- EnvironmentError | |
| | +-- IOError | |
| | +-- OSError | |
| | +-- WindowsError (Windows) | |
| | +-- VMSError (VMS) | |
| +-- EOFError | |
| +-- ImportError | |
| +-- LookupError | |
| | +-- IndexError | |
| | +-- KeyError | |
| +-- MemoryError | |
| +-- NameError | |
| | +-- UnboundLocalError | |
| +-- ReferenceError | |
| +-- RuntimeError | |
| | +-- NotImplementedError | |
| +-- SyntaxError | |
| | +-- IndentationError | |
| | +-- TabError | |
| +-- SystemError | |
| +-- TypeError | |
| +-- ValueError | |
| +-- UnicodeError | |
| +-- UnicodeDecodeError | |
| +-- UnicodeEncodeError | |
| +-- UnicodeTranslateError | |
+-- Warning | |
+-- DeprecationWarning | |
+-- PendingDeprecationWarning | |
+-- RuntimeWarning | |
+-- SyntaxWarning | |
+-- UserWarning | |
+-- FutureWarning | |
+-- ImportWarning | |
+-- UnicodeWarning | |
+-- BytesWarning | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment