Skip to content

Instantly share code, notes, and snippets.

@dketov
Created December 12, 2011 15:52
Show Gist options
  • Save dketov/1467982 to your computer and use it in GitHub Desktop.
Save dketov/1467982 to your computer and use it in GitHub Desktop.
Классы исключений
# -*- encoding: utf-8 -*-
"""
Деление на ноль
"""
try: 1/0
except ZeroDivisionError:
print "caught divide-by-0 attempt"
# -*- 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"
# -*- 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