Lecture overview -- Keyboard shortcut: 'u'  Previous page: Raising an exception in an exception handler -- Keyboard shortcut: 'p'  Next page: Recommendations about exception handling [Section] -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Help page about these notes  Alphabetic index  Course home  Page 27 : 30
Object-oriented Programming in C#
Exception Handling
Comparison with exception handling in Java

The catch or specify principle: A method either catches and handles an exception, or it specifies that it may throw the exception

  • In Java

    • the signatures of methods are extended with a throws clause

      • tells that the method may throw a given exceptions

    • a branch of the exception hierarchy - the so-called RuntimeExceptions - is exempted from the catch or specify principle

  • In C#

    • all exceptions correspond to Java RuntimeExceptions

/user/normark/oop-csharp-1/sources/c-sharp/exception/java-comparison/CatchOrSpecifyDemo0.javaA Java program - does not compile. This program is explained

Main calls explosion without handling or specifying Problem.

/user/normark/oop-csharp-1/sources/c-sharp/exception/java-comparison/CatchOrSpecifyDemo1.javaA Java program - main handles Problem. This program is explained

/user/normark/oop-csharp-1/sources/c-sharp/exception/java-comparison/CatchOrSpecifyDemo2.javaA Java program - main specifies Problem. This program is explained