Ejemplo n.º 1
0
        public int Division(int firstArgument, int secondArgument)
        {
            try
            {
                if (firstArgument == 0 && secondArgument == 0)
                {
                    CustomFaultExeption fault = new CustomFaultExeption();
                    fault.TypeOfExeption = "ValidationFault";
                    fault.Description    = "Invalid arguments";
                    fault.Message        = "Both arguments can't be zero! ";
                    fault.Result         = false;
                    throw  new FaultException <CustomFaultExeption>(fault);
                }
                return(firstArgument / secondArgument);
            }
            catch (DivideByZeroException exception)
            {
                CustomFaultExeption fault = new CustomFaultExeption();
                fault.TypeOfExeption = "DivideByZeroException";
                fault.Result         = false;
                fault.Description    = "Divizion by zero";
                fault.Message        = exception.Message;

                throw new FaultException <CustomFaultExeption>(fault);
            }
        }
Ejemplo n.º 2
0
        public int Substraction(int firstArgument, int secondArgument)
        {
            int result;

            try
            {
                result = checked (firstArgument - secondArgument);
            }
            catch (OverflowException e)
            {
                CustomFaultExeption fault = new CustomFaultExeption();
                fault.TypeOfExeption = "OverflowException";
                fault.Result         = false;
                fault.Description    = "Overflow detected!";
                fault.Message        = e.Message;
                throw new FaultException <CustomFaultExeption>(fault);
            }
            return(result);
        }