6. 내장 예외
************

Exceptions should be class objects.   The exceptions are defined in
the module "exceptions".  This module never needs to be imported
explicitly: the exceptions are provided in the built-in namespace as
well as the "exceptions" module.

For class exceptions, in a "try" statement with an "except" clause
that mentions a particular class, that clause also handles any
exception classes derived from that class (but not exception classes
from which *it* is derived).  Two exception classes that are not
related via subclassing are never equivalent, even if they have the
same name.

The built-in exceptions listed below can be generated by the
interpreter or built-in functions.  Except where mentioned, they have
an "associated value" indicating the detailed cause of the error.
This may be a string or a tuple containing several items of
information (e.g., an error code and a string explaining the code).
The associated value is the second argument to the "raise" statement.
If the exception class is derived from the standard root class
"BaseException", the associated value is present as the exception
instance's "args" attribute.

사용자 코드는 내장 예외를 일으킬 수 있습니다. 이것은 예외 처리기를 검
사하거나 인터프리터가 같은 예외를 발생시키는 상황과 "같은" 에러 조건을
보고하는 데 사용할 수 있습니다. 그러나 사용자 코드가 부적절한 에러를
발생시키는 것을 막을 방법이 없음을 유의하십시오.

내장 예외 클래스는 새 예외를 정의하기 위해 서브 클래싱 될 수 있습니다.
"BaseException" 이 아니라 "Exception" 클래스 나 그 서브 클래스 중 하나
에서 새로운 예외를 파생시킬 것을 권장합니다. 예외 정의에 대한 더 많은
정보는 파이썬 자습서의 사용자 정의 예외 에 있습니다.

The following exceptions are only used as base classes for other
exceptions.

exception BaseException

   The base class for all built-in exceptions.  It is not meant to be
   directly inherited by user-defined classes (for that, use
   "Exception").  If "str()" or "unicode()" is called on an instance
   of this class, the representation of the argument(s) to the
   instance are returned, or the empty string when there were no
   arguments.

   버전 2.5에 추가.

   args

      The tuple of arguments given to the exception constructor.  Some
      built-in exceptions (like "IOError") expect a certain number of
      arguments and assign a special meaning to the elements of this
      tuple, while others are usually called only with a single string
      giving an error message.

exception Exception

   모든 시스템 종료 외의 내장 예외는 이 클래스 파생됩니다. 모든 사용자
   정의 예외도 이 클래스에서 파생되어야 합니다.

   버전 2.5으로 변경: Changed to inherit from "BaseException".

exception StandardError

   The base class for all built-in exceptions except "StopIteration",
   "GeneratorExit", "KeyboardInterrupt" and "SystemExit".
   "StandardError" itself is derived from "Exception".

exception ArithmeticError

   다양한 산술 에러가 일으키는 내장 예외들의 베이스 클래스:
   "OverflowError", "ZeroDivisionError", "FloatingPointError".

exception BufferError

   버퍼 관련 연산을 수행할 수 없을 때 발생합니다.

exception LookupError

   매핑 또는 시퀀스에 사용된 키 나 인덱스가 잘못되었을 때 발생하는 예
   외의 베이스 클래스: "IndexError", "KeyError". "codecs.lookup()" 은
   이 예외를 직접 일으킬 수 있습니다.

exception EnvironmentError

   The base class for exceptions that can occur outside the Python
   system: "IOError", "OSError".  When exceptions of this type are
   created with a 2-tuple, the first item is available on the
   instance's "errno" attribute (it is assumed to be an error number),
   and the second item is available on the "strerror" attribute (it is
   usually the associated error message).  The tuple itself is also
   available on the "args" attribute.

   버전 1.5.2에 추가.

   When an "EnvironmentError" exception is instantiated with a
   3-tuple, the first two items are available as above, while the
   third item is available on the "filename" attribute.  However, for
   backwards compatibility, the "args" attribute contains only a
   2-tuple of the first two constructor arguments.

   The "filename" attribute is "None" when this exception is created
   with other than 3 arguments.  The "errno" and "strerror" attributes
   are also "None" when the instance was created with other than 2 or
   3 arguments. In this last case, "args" contains the verbatim
   constructor arguments as a tuple.

The following exceptions are the exceptions that are actually raised.

exception AssertionError

   "assert" 문이 실패할 때 발생합니다.

exception AttributeError

   어트리뷰트 참조(어트리뷰트 참조를 보세요)나 대입이 실패할 때 발생합
   니다. (객체가 어트리뷰트 참조나 어트리뷰트 대입을 아예 지원하지 않
   으면 "TypeError" 가 발생합니다.)

exception EOFError

   Raised when one of the built-in functions ("input()" or
   "raw_input()") hits an end-of-file condition (EOF) without reading
   any data. (N.B.: the "file.read()" and "file.readline()" methods
   return an empty string when they hit EOF.)

exception FloatingPointError

   부동 소수점 연산이 실패할 때 발생합니다. 이 예외는 항상 정의되어 있
   지만, 파이썬이 "--with-fpectl" 옵션으로 설정되었거나,
   "WANT_SIGFPE_HANDLER" 심볼이 "pyconfig.h" 파일에 정의되어있을 때만
   발생합니다.

exception GeneratorExit

   Raised when a *generator*'s "close()" method is called.  It
   directly inherits from "BaseException" instead of "StandardError"
   since it is technically not an error.

   버전 2.5에 추가.

   버전 2.6으로 변경: Changed to inherit from "BaseException".

exception IOError

   Raised when an I/O operation (such as a "print" statement, the
   built-in "open()" function or a method of a file object) fails for
   an I/O-related reason, e.g., "file not found" or "disk full".

   This class is derived from "EnvironmentError".  See the discussion
   above for more information on exception instance attributes.

   버전 2.6으로 변경: Changed "socket.error" to use this as a base
   class.

exception ImportError

   Raised when an "import" statement fails to find the module
   definition or when a "from ... import" fails to find a name that is
   to be imported.

exception IndexError

   Raised when a sequence subscript is out of range.  (Slice indices
   are silently truncated to fall in the allowed range; if an index is
   not a plain integer, "TypeError" is raised.)

exception KeyError

   매핑 (딕셔너리) 키가 기존 키 집합에서 발견되지 않을 때 발생합니다.

exception KeyboardInterrupt

   Raised when the user hits the interrupt key (normally "Control-C"
   or "Delete").  During execution, a check for interrupts is made
   regularly. Interrupts typed when a built-in function "input()" or
   "raw_input()" is waiting for input also raise this exception. The
   exception inherits from "BaseException" so as to not be
   accidentally caught by code that catches "Exception" and thus
   prevent the interpreter from exiting.

   버전 2.5으로 변경: Changed to inherit from "BaseException".

exception MemoryError

   작업에 메모리가 부족하지만, 상황이 여전히 (일부 객체를 삭제해서) 복
   구될 수 있는 경우 발생합니다. 연관된 값은 어떤 종류의 (내부) 연산이
   메모리를 다 써 버렸는지를 나타내는 문자열입니다. 하부 메모리 관리
   아키텍처(C의 "malloc()" 함수)때문에, 인터프리터가 항상 이 상황을 완
   벽하게 복구할 수 있는 것은 아닙니다; 그런데도 통제를 벗어난 프로그
   램이 원인인 경우를 위해, 스택 트레이스백을 인쇄할 수 있도록 예외를
   일으킵니다.

exception NameError

   지역 또는 전역 이름을 찾을 수 없을 때 발생합니다. 이는 정규화되지
   않은 이름에만 적용됩니다. 연관된 값은 찾을 수 없는 이름을 포함하는
   에러 메시지입니다.

exception NotImplementedError

   This exception is derived from "RuntimeError".  In user defined
   base classes, abstract methods should raise this exception when
   they require derived classes to override the method.

   버전 1.5.2에 추가.

exception OSError

   This exception is derived from "EnvironmentError".  It is raised
   when a function returns a system-related error (not for illegal
   argument types or other incidental errors).  The "errno" attribute
   is a numeric error code from "errno", and the "strerror" attribute
   is the corresponding string, as would be printed by the C function
   "perror()". See the module "errno", which contains names for the
   error codes defined by the underlying operating system.

   For exceptions that involve a file system path (such as "chdir()"
   or "unlink()"), the exception instance will contain a third
   attribute, "filename", which is the file name passed to the
   function.

   버전 1.5.2에 추가.

exception OverflowError

   Raised when the result of an arithmetic operation is too large to
   be represented.  This cannot occur for long integers (which would
   rather raise "MemoryError" than give up) and for most operations
   with plain integers, which return a long integer instead.  Because
   of the lack of standardization of floating point exception handling
   in C, most floating point operations also aren't checked.

exception ReferenceError

   이 예외는 "weakref.proxy()" 함수가 만든 약한 참조 프락시가 이미 가
   비지 수집된 참조 대상의 어트리뷰트를 액세스하는 데 사용될 때 발생합
   니다. 약한 참조에 대한 더 자세한 정보는 "weakref" 모듈을 보십시오.

   버전 2.2에 추가: Previously known as the "weakref.ReferenceError"
   exception.

exception RuntimeError

   다른 범주에 속하지 않는 에러가 감지될 때 발생합니다. 연관된 값은 정
   확히 무엇이 잘못되었는지를 나타내는 문자열입니다.

exception StopIteration

   Raised by an *iterator*'s "next()" method to signal that there are
   no further values.  This is derived from "Exception" rather than
   "StandardError", since this is not considered an error in its
   normal application.

   버전 2.2에 추가.

exception SyntaxError

   Raised when the parser encounters a syntax error.  This may occur
   in an "import" statement, in an "exec" statement, in a call to the
   built-in function "eval()" or "input()", or when reading the
   initial script or standard input (also interactively).

   세부 사항을 쉽게 확인할 수 있도록, 이 클래스의 인스턴스에는
   "filename", "lineno", "offset" 및 "text" 어트리뷰트가 있습니다. 예
   외 인스턴스의 "str()"은 메시지만 돌려줍니다.

exception IndentationError

   잘못된 들여쓰기와 관련된 문법 오류의 베이스 클래스입니다.
   "SyntaxError" 의 서브 클래스입니다.

exception TabError

   들여쓰기가 일관성없는 탭과 스페이스 사용을 포함하는 경우 발생합니다
   . "IndentationError" 의 서브 클래스입니다.

exception SystemError

   인터프리터가 내부 에러를 발견했지만, 모든 희망을 포기할 만큼 상황이
   심각해 보이지는 않을 때 발생합니다. 연관된 값은 무엇이 잘못되었는지
   (저수준의 용어로) 나타내는 문자열입니다.

   이것을 파이썬 인터프리터의 저자 또는 관리자에게 알려야 합니다. 파이
   썬 인터프리터의 버전 ("sys.version"; 대화식 파이썬 세션의 시작 부분
   에도 출력됩니다), 정확한 에러 메시지 (예외의 연관된 값) 그리고 가능
   하다면 에러를 일으킨 프로그램의 소스를 제공해 주십시오.

exception SystemExit

   This exception is raised by the "sys.exit()" function.  When it is
   not handled, the Python interpreter exits; no stack traceback is
   printed.  If the associated value is a plain integer, it specifies
   the system exit status (passed to C's "exit()" function); if it is
   "None", the exit status is zero; if it has another type (such as a
   string), the object's value is printed and the exit status is one.

   Instances have an attribute "code" which is set to the proposed
   exit status or error message (defaulting to "None"). Also, this
   exception derives directly from "BaseException" and not
   "StandardError", since it is not technically an error.

   "sys.exit()" 에 대한 호출은 예외로 변환되어 뒷정리 처리기 ("try" 문
   의 "finally" 절) 가 실행될 수 있도록 합니다. 그래서 디버거는 제어권
   을 잃을 위험 없이 스크립트를 실행할 수 있습니다. 즉시 종료가 절대적
   으로 필요한 경우에는 "os._exit()" 함수를 사용할 수 있습니다 (예를
   들어, "os.fork()" 호출 후의 자식 프로세스에서).

   The exception inherits from "BaseException" instead of
   "StandardError" or "Exception" so that it is not accidentally
   caught by code that catches "Exception".  This allows the exception
   to properly propagate up and cause the interpreter to exit.

   버전 2.5으로 변경: Changed to inherit from "BaseException".

exception TypeError

   연산이나 함수가 부적절한 형의 객체에 적용될 때 발생합니다. 연관된
   값은 형 불일치에 대한 세부 정보를 제공하는 문자열입니다.

exception UnboundLocalError

   함수 나 메서드에서 지역 변수를 참조하지만, 해당 변수에 값이 연결되
   지 않으면 발생합니다. 이것은 "NameError" 의 서브 클래스입니다.

   버전 2.0에 추가.

exception UnicodeError

   유니코드 관련 인코딩 또는 디코딩 에러가 일어날 때 발생합니다.
   "ValueError" 의 서브 클래스입니다.

   "UnicodeError" 는 인코딩이나 디코딩 에러를 설명하는 어트리뷰트를 가
   지고 있습니다. 예를 들어, "err.object[err.start:err.end]" 는 코덱이
   실패한 잘못된 입력을 제공합니다.

   encoding

      에러를 발생시킨 인코딩의 이름입니다.

   reason

      구체적인 코덱 오류를 설명하는 문자열입니다.

   object

      코덱이 인코딩 또는 디코딩하려고 시도한 객체입니다.

   start

      "object" 에 있는 잘못된 데이터의 최초 인덱스입니다.

   end

      "object" 에 있는 마지막으로 잘못된 데이터의 바로 다음 인덱스입니
      다.

   버전 2.0에 추가.

exception UnicodeEncodeError

   인코딩 중에 유니코드 관련 에러가 일어나면 발생합니다.
   "UnicodeError" 의 서브 클래스입니다.

   버전 2.3에 추가.

exception UnicodeDecodeError

   디코딩 중에 유니코드 관련 에러가 일어나면 발생합니다.
   "UnicodeError" 의 서브 클래스입니다.

   버전 2.3에 추가.

exception UnicodeTranslateError

   번역 중에 유니코드 관련 에러가 일어나면 발생합니다. "UnicodeError"
   의 서브 클래스입니다.

   버전 2.3에 추가.

exception ValueError

   Raised when an operation or function receives an argument that has
   the right type but an inappropriate value, and the situation is not
   described by a more precise exception such as "IndexError".

exception VMSError

   Only available on VMS.  Raised when a VMS-specific error occurs.

exception WindowsError

   Raised when a Windows-specific error occurs or when the error
   number does not correspond to an "errno" value.  The "winerror" and
   "strerror" values are created from the return values of the
   "GetLastError()" and "FormatMessage()" functions from the Windows
   Platform API. The "errno" value maps the "winerror" value to
   corresponding "errno.h" values. This is a subclass of "OSError".

   버전 2.0에 추가.

   버전 2.5으로 변경: Previous versions put the "GetLastError()" codes
   into "errno".

exception ZeroDivisionError

   나누기 또는 모듈로 연산의 두 번째 인자가 0일 때 발생합니다. 연관된
   값은 피연산자의 형과 연산을 나타내는 문자열입니다.

다음 예외는 경고 범주로 사용됩니다; 자세한 정보는 "warnings" 모듈을 보
십시오.

exception Warning

   경고 범주의 베이스 클래스입니다.

exception UserWarning

   사용자 코드에 의해 만들어지는 경고의 베이스 클래스입니다.

exception DeprecationWarning

   폐지된 기능에 대한 경고의 베이스 클래스입니다.

exception PendingDeprecationWarning

   장래에 폐지될 기능에 관한 경고의 베이스 클래스입니다.

exception SyntaxWarning

   모호한 문법에 대한 경고의 베이스 클래스입니다.

exception RuntimeWarning

   모호한 실행 시간 동작에 대한 경고의 베이스 클래스입니다.

exception FutureWarning

   장래에 의미상으로 변경되는 구조물에 관한 경고의 베이스 클래스입니다
   .

exception ImportWarning

   모듈 임포트에 있을 수 있는 실수에 대한 경고의 베이스 클래스입니다.

   버전 2.5에 추가.

exception UnicodeWarning

   유니코드와 관련된 경고의 베이스 클래스입니다.

   버전 2.5에 추가.

exception BytesWarning

   Base class for warnings related to bytes and bytearray.

   버전 2.6에 추가.


6.1. 예외 계층 구조
===================

내장 예외의 클래스 계층 구조는 다음과 같습니다:

   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
