Page 5 : 30
Object-oriented Programming in C#
Exception Handling
* Fundamental Questions about Exception Handling
What is the motivation?
What is an error?
What is normal? What is exceptional?
Examples of normal and exceptional aspects
When are errors detected?
How are errors handled?
Where are errors handled?
* Conventional Exception Handling
Exception Handling Approaches
Mixing normal and exceptional cases
* Object-oriented Exception Handling
Errors as Objects
Classification of Errors
* Exceptions and Exception Handling in C#
Exceptions in a C# program
The try-catch statement C#
Handling exceptions in C#
The hierarchy of exceptions in C#
The class System.Exception in C#
Handling more than one type of exception in C#
Propagation of exceptions in C#
Raising and throwing exceptions in C#
Try-catch with a finally clause
Rethrowing an exception
Raising an exception in an exception handler
Comparison with exception handling in Java
* Recommendations about exception handling
Recommendations about exception handling
Recommendations about exception handling
Examples of normal and exceptional aspects
Normal aspects and exceptional aspects - anticipated or non-anticipated
public static long Factorial(int n){ if (n == 0) return 1; else return n * Factorial(n - 1); }
A recursive Factorial function.
1.
Negative input
2.
Wrong type of input
3.
Wrong type of multiplication
4.
Numeric overflow
5.
Out of memory
6.
Loss of power
7.
Machine failure
8.
Sun failure
An iterative Factorial function.
An iterative Factorial function with a precondition - not C# 3.0.