Ausnahmebehandlung in Java

Die Behandlung von Laufzeitfehlern (z. B. IO-Fehlern) wird in Java nicht dem Entwickler alleine überlassen. Durch das Konzept der Exceptions ist der Code zur Fehlerbehandlung schon syntaktisch von der "normalen" Programmlogik getrennt.

try {
   statements
   ...
} catch (Exception e) {
   statements
   ...
} finally {
   ....
}

void method() throws Exception {
   ...
   throw new Exception("Alles ist hin!");
}

Die Behandlung von Exceptions durch den Compiler folgt dabei der Catch or Specify Direktive: Ein Methodenaufruf muss die von dieser deklarierten möglichen Exceptions entweder behandeln oder die den Code enthaltende Methode muss diese Exception ebenfalls deklarieren. Eine Ausnahme bilden die %JAVADOC{java.lang.RuntimeException}%s.

Exceptions haben eine eigene Klassen-Hierarchie basierend auf dem Interface %JAVADOC{java.lan.Throwable}%.

-- Christo - 13 Nov 2003
I Attachment Action Size Date Who CommentSorted descending
ExceptionSample.javajava ExceptionSample.java manage 1020 bytes 2003-11-13 - 17:43 UnknownUser Programmbeispiel für Exceptions
ExceptionTest.javajava ExceptionTest.java manage 783 bytes 2003-11-14 - 14:46 UnknownUser Programmbeispiel für Exceptions
Topic revision: r3 - 2003-11-14, ChristopherHuhn
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding GSI Wiki? Send feedback | Legal notice | Privacy Policy (german)