Passing Exceptions on to the Caller: Caller Confuse

image_pdfimage_print
   

/*
A Programmer's Introduction to C# (Second Edition)
by Eric Gunnerson

Publisher: Apress  L.P.
ISBN: 1-893115-62-3
*/

// 04 - Exception HandlingPassing Exceptions on to the CallerCaller Confuse
// copyright 2000 Eric Gunnerson
using System;

public class CallerConfuse
{
    public static void Main()
    {
        Summer summer = new Summer();
        try
        {
            summer.DoAverage();
        }
        catch (Exception e)
        {
            Console.WriteLine("Exception {0}", e);
        }
    }
}
public class Summer
{
    int    sum = 0;
    int    count = 0;
    float    average;
    public void DoAverage()
    {
        try
        {
            average = sum / count;
        }
        catch (DivideByZeroException e)
        {
            // do some cleanup here
            throw;
        }
    }
}