// $Id: exceptions.csharp,v 1.0 2002/09/28 10:21:00 dada Exp $
// http://dada.perl.it/shootout/
// contributed by Erik Saltwell

using System;

namespace Exceptions
{
    class LoException : System.Exception
    {
        public LoException(){}
    }

    class HiException : System.Exception 
    {
        public HiException(){}
    }

    public class App 
    {
        static int Lo = 0;
        static int Hi = 0;
        static int count=0;
        public static void Main(string[] args)
        {
            int n = int.Parse(args[0]);
            for (count=0; count<n; count++) 
            {
                SomeFunction();
            }
            System.Text.StringBuilder bldr = new System.Text.StringBuilder(100);
            bldr.Append("Exceptions: HI=").Append(Hi).Append(" / LO=").Append(Lo);
            Console.WriteLine(bldr.ToString());
        }

        public static void SomeFunction() 
        {
            try 
            {
                HiFunction();
            } 
            catch (Exception e) 
            {
                Console.WriteLine("We shouldn't get here: " + e.Message);
            }
        }

        public static void HiFunction() 
        {
            try 
            {
                LoFunction();
            } 
            catch (HiException) 
            {
                Hi++;
            }
        }
        public static void LoFunction()
        {
            try 
            {
                BlowUp();
            } 
            catch (LoException) 
            {
                Lo++;
            }
        }
        public static void BlowUp() 
        {
            if ((count & 1) == 0) 
            {
                throw new LoException();
            } 
            else 
            {
                throw new HiException();
            }
        }
    }
}