コード例 #1
0
ファイル: Calculator.svc.cs プロジェクト: Vistor25/WCFService
        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);
            }
        }
コード例 #2
0
ファイル: Calculator.svc.cs プロジェクト: Vistor25/WCFService
        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);
        }