EXCEPTION
Wichtige Exception

Exception Erläuterung
BaseException Dies ist die Basis-Klasse aller Exceptions
ArithmeticError Ausgelöst durch Arithmetik-Fehler:
- OverflowError (Wert ist zu groß für den Datentyp)
- ZeroDivisionError
- FloatingPointError
AttributeError Es wird versucht, ein Attribut einer Instanz aufzurufen. Das Attribut ist aber nicht definiert. Diesen Fehler gibt es nciht in Java oder C#.
EOFError Es wird versucht, über das Ende einer Datei zu lesen.
IOError Die Datei ist nicht vorhanden oder man hat keine Rechte.
IndexError Java: IndexOutOfBoundException (kennt keiner)
MemoryError Zu wenig Speicher.
OverflowError Der Wert einer Berechnung ist zu groß für den Datentyp.
ValueError Ein Argument einer Funktion hat den korrekten Typ, aber den falschen Inhalt.
Konvertierungsfehler.

Beispiel:
try:
__a = int('abc')
except ValueError as e:
__print("fehlerhafte Zahl")

Als Funktion:
def isfloat(value):
try:
__float(value)
__return True
except:
__return False
ZeroDivisionError Division durch Null.



Typen der 
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.

    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.

6.3.2	exception ArithmeticError

    The base class for those built-in exceptions that are raised for various arithmetic errors: OverflowError, ZeroDivisionError, FloatingPointError.

6.3.3	exception AttributeError

    Raised when an attribute reference (see Attribute references) or assignment fails. (When an object does not support attribute references or attribute assignments at all, TypeError is raised.)

6.3.4	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.)

6.3.5	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.


6.3.6	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.)


6.3.7	exception MemoryError

    Raised when an operation runs out of memory but the situation may still be rescued (by deleting some objects). The associated value is a string indicating what kind of (internal) operation ran out of memory. Note that because of the underlying memory management architecture (C's malloc() function), the interpreter may not always be able to completely recover from this situation; it nevertheless raises an exception so that a stack traceback can be printed, in case a run-away program was the cause.


6.3.8	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.


6.3.9	exception ValueError

    Raised when a built-in 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.

Beispiel:
	try:
		a = int('abc')
	except ValueError as e:
		print("fehlerhafte Zahl")

def isfloat(value):
  try:
    float(value)
    return True
  except:
    return False


6.3.10	exception ZeroDivisionError

    Raised when the second argument of a division or modulo operation is zero. The associated value is a string indicating the type of the operands and the operation.

The following exceptions are used as warning categories; see the warnings module for more information.


6.4	Eigene Exception auslösen


def fakultaet(n):
	if n < 0:
		raise fakultaet
	p=1
	for i in range(2,n+1):						# Ende zählt nicht mit
		p *= i
	return p



Mengen/Sets
Functions