// Returns true if the expected result is right
 // Returns false if the expected result is wrong
 public bool PosTest1()
 {
     bool retVal = true;
     TestLibrary.TestFramework.BeginScenario("PosTest1: Create a new instance of OverflowException.");
     try
     {
         string expectValue = "HELLO";
         OverflowException myException = new OverflowException(expectValue);
         if (myException == null)
         {
             TestLibrary.TestFramework.LogError("001.1", "OverflowException instance can not create correctly.");
             retVal = false;
         }
         if (myException.Message != expectValue)
         {
             TestLibrary.TestFramework.LogError("001.2", "the Message should return " + expectValue);
             retVal = false;
         }
     }
     catch (Exception e)
     {
         TestLibrary.TestFramework.LogError("001.0", "Unexpected exception: " + e);
         retVal = false;
     }
     return retVal;
 }
Example #2
0
        public override Envelope <TItem, TBorrowerId> Borrow(TBorrowerId borrower, string membershipId)
        {
            TItem tItem = default(TItem);

            this.Trace("Shared Item store Borrow");
            if (this.cache.TryLockKey(membershipId, out tItem))
            {
                TraceHelper.Current.SharedStoreTookFromCache(borrower.ToString(), typeof(TItem).ToString());
            }
            else
            {
                TraceHelper.Current.SharedStoreCreatedNew(borrower.ToString(), typeof(TItem).ToString());
                TItem tItem1 = base.Factory.Create(borrower, membershipId);
                try
                {
                    this.cache.AddOrLockKey(membershipId, tItem1, out tItem);
                }
                catch (OverflowException overflowException1)
                {
                    OverflowException overflowException = overflowException1;
                    overflowException.Trace("Ignoring exception");
                }
            }
            return(new Envelope <TItem, TBorrowerId>(tItem, membershipId, this, borrower));
        }
 // Returns true if the expected result is right
 // Returns false if the expected result is wrong
 public bool PosTest2()
 {
     bool retVal = true;
     TestLibrary.TestFramework.BeginScenario("PosTest2: the parameter string is null.");
     try
     {
         string expectValue = null;
         OverflowException myException = new OverflowException(expectValue);
         if (myException == null)
         {
             TestLibrary.TestFramework.LogError("002.1", "OverflowException instance can not create correctly.");
             retVal = false;
         }
         if (myException.Message == expectValue)
         {
             TestLibrary.TestFramework.LogError("002.2", "the Message should return the default value.");
             retVal = false;
         }
     }
     catch (Exception e)
     {
         TestLibrary.TestFramework.LogError("002.0", "Unexpected exception: " + e);
         retVal = false;
     }
     return retVal;
 }
Example #4
0
        public void ConnectionString_MaxPoolSize_Invalid()
        {
            SqlConnection cn = new SqlConnection();

            // negative number
            ArgumentException ex = Assert.Throws <ArgumentException>(() => cn.ConnectionString = "Max Pool Size=-1");

            // Invalid value for key 'max pool size'
            Assert.Null(ex.InnerException);
            Assert.NotNull(ex.Message);
            Assert.True(ex.Message.IndexOf("'max pool size'") != -1);
            Assert.Null(ex.ParamName);

            // invalid number
            ex = Assert.Throws <ArgumentException>(() => cn.ConnectionString = "max Pool size=BB");
            // Invalid value for key 'max pool size'
            Assert.NotNull(ex.InnerException);
            Assert.Equal(typeof(FormatException), ex.InnerException.GetType());
            Assert.NotNull(ex.Message);
            Assert.True(ex.Message.IndexOf("'max pool size'") != -1);
            Assert.Null(ex.ParamName);

            // Input string was not in a correct format
            FormatException fe = (FormatException)ex.InnerException;

            Assert.Null(fe.InnerException);
            Assert.NotNull(fe.Message);

            // overflow
            ex = Assert.Throws <ArgumentException>(() => cn.ConnectionString = "max pool size=2147483648");
            // Invalid value for key 'max pool size'
            Assert.NotNull(ex.InnerException);
            Assert.Equal(typeof(OverflowException), ex.InnerException.GetType());
            Assert.NotNull(ex.Message);
            Assert.True(ex.Message.IndexOf("'max pool size'") != -1);
            Assert.Null(ex.ParamName);

            // Value was either too large or too small for an Int32
            OverflowException oe = (OverflowException)ex.InnerException;

            Assert.Null(oe.InnerException);
            Assert.NotNull(oe.Message);

            // less than minimum (1)
            ex = Assert.Throws <ArgumentException>(() => cn.ConnectionString = "Min Pool Size=0;Max Pool Size=0");
            // Invalid value for key 'max pool size'
            Assert.Null(ex.InnerException);
            Assert.NotNull(ex.Message);
            Assert.True(ex.Message.IndexOf("'max pool size'") != -1);
            Assert.Null(ex.ParamName);

            // less than min pool size
            ex = Assert.Throws <ArgumentException>(() => cn.ConnectionString = "Min Pool Size=5;Max Pool Size=4");
            // Invalid min or max pool size values, min
            // pool size cannot be greater than the max
            // pool size
            Assert.Null(ex.InnerException);
            Assert.NotNull(ex.Message);
            Assert.Null(ex.ParamName);
        }
Example #5
0
        public override void Return(Envelope <TItem, TBorrowerId> envelope)
        {
            ExclusiveItemStore <TItem, TBorrowerId> .BorrowerAccount borrowerAccount = null;
            this.Trace("Exclusive item store Return");
            try
            {
                if (!this.borrowersDictionary.TryLockKey(envelope.Borrower, out borrowerAccount))
                {
                    ExclusiveItemStore <TItem, TBorrowerId> .BorrowerAccount borrowerAccount1 = new ExclusiveItemStore <TItem, TBorrowerId> .BorrowerAccount(envelope.MembershipId, this, this.borrowerAccountMaxCacheSize);

                    this.borrowersDictionary.AddOrLockKey(envelope.Borrower, borrowerAccount1, out borrowerAccount);
                }
                if (envelope.MembershipId == borrowerAccount.MembershipId)
                {
                    try
                    {
                        borrowerAccount.IdleQueue.Enqueue(envelope.Item);
                    }
                    catch (OverflowException overflowException1)
                    {
                        OverflowException overflowException = overflowException1;
                        overflowException.Trace("Ignoring exception");
                    }
                }
            }
            finally
            {
                this.borrowersDictionary.TryUnlockKey(envelope.Borrower);
            }
        }
        public static void Ctor_String()
        {
            string message   = "overflow";
            var    exception = new OverflowException(message);

            ExceptionHelpers.ValidateExceptionProperties(exception, hResult: COR_E_OVERFLOW, message: message);
        }
Example #7
0
        /// <summary>
        /// Gets the sitemap XML for the current site. If there are more than 50,000 sitemap nodes
        /// (The maximum allowed before you have to use a sitemap index file), the list is truncated and an error is logged.
        /// See http://www.sitemaps.org/protocol.html for more information.
        /// </summary>
        /// <returns>The sitemap XML for the current site.</returns>
        public string GetSitemapXml()
        {
            IReadOnlyCollection <SitemapNode> sitemapNotes = this.GetSitemapNodes();

            if (sitemapNotes.Count > MaximumSitemapNodeCount)
            {
                OverflowException overflowException = new OverflowException(string.Format("There are too many sitemap nodes, the collection has been truncated. If you want to use more than 50,000, you must use a sitemap index file (See http://www.sitemaps.org/protocol.html). Count:<{0}>.", sitemapNotes.Count));
                this.loggingService.Log(overflowException);
            }

            XNamespace xmlns = SitemapsNamespace;
            XElement   root  = new XElement(xmlns + "urlset");

            foreach (SitemapNode sitemapNode in sitemapNotes.Take(MaximumSitemapNodeCount))
            {
                root.Add(
                    new XElement(xmlns + "url",
                                 new XElement(xmlns + "loc", Uri.EscapeUriString(sitemapNode.Url)),
                                 sitemapNode.LastModified == null ? null : new XElement(xmlns + "lastmod", sitemapNode.LastModified.Value.ToLocalTime().ToString("yyyy-MM-ddTHH:mm:sszzz")),
                                 sitemapNode.Frequency == null ? null : new XElement(xmlns + "changefreq", sitemapNode.Frequency.Value.ToString().ToLowerInvariant()),
                                 sitemapNode.Priority == null ? null : new XElement(xmlns + "priority", sitemapNode.Priority.Value.ToString("F1", CultureInfo.InvariantCulture))));
            }

            return(root.ToString());
        }
        internal static Exception ParameterConversionFailed(object value, Type destType, Exception inner)
        {
            Debug.Assert(null != value, "null value on conversion failure");
            Debug.Assert(null != inner, "null inner on conversion failure");

            Exception e;
            string    message = SR.GetString(SR.ADP_ParameterConversionFailed, value.GetType().Name, destType.Name);

            if (inner is ArgumentException)
            {
                e = new ArgumentException(message, inner);
            }
            else if (inner is FormatException)
            {
                e = new FormatException(message, inner);
            }
            else if (inner is InvalidCastException)
            {
                e = new InvalidCastException(message, inner);
            }
            else if (inner is OverflowException)
            {
                e = new OverflowException(message, inner);
            }
            else
            {
                e = inner;
            }
            return(e);
        }
Example #9
0
    // Returns true if the expected result is right
    // Returns false if the expected result is wrong
    public bool PosTest2()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest2: the parameter string is null.");
        try
        {
            string            expectValue  = null;
            ArgumentException dpoExpection = new ArgumentException();
            OverflowException myException  = new OverflowException(expectValue, dpoExpection);
            if (myException == null)
            {
                TestLibrary.TestFramework.LogError("002.1", "OverflowException instance can not create correctly.");
                retVal = false;
            }
            if (myException.Message == expectValue)
            {
                TestLibrary.TestFramework.LogError("002.2", "the Message should return the default value.");
                retVal = false;
            }
            if (!(myException.InnerException is ArgumentException))
            {
                TestLibrary.TestFramework.LogError("002.3", "the InnerException should return OverflowException.");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002.0", "Unexpected exception: " + e);
            retVal = false;
        }
        return(retVal);
    }
Example #10
0
        protected override BitStream InternalValueToBitStream()
        {
            ulong bits;

            dynamic value = GetNumber(InternalValue);

            if (value > 0 && (ulong)value > MaxValue)
            {
                string msg   = string.Format("Error, {0} value '{1}' is greater than the maximum {2}-bit {3} number.", debugName, value, lengthAsBits, Signed ? "signed" : "unsigned");
                var    inner = new OverflowException(msg);
                throw new SoftException(inner);
            }

            if (value < 0 && (long)value < MinValue)
            {
                string msg   = string.Format("Error, {0} value '{1}' is less than the minimum {2}-bit {3} number.", debugName, value, lengthAsBits, Signed ? "signed" : "unsigned");
                var    inner = new OverflowException(msg);
                throw new SoftException(inner);
            }

            if (LittleEndian)
            {
                bits = LittleBitWriter.GetBits(value, (int)lengthAsBits);
            }
            else
            {
                bits = BigBitWriter.GetBits(value, (int)lengthAsBits);
            }

            var bs = new BitStream();

            bs.WriteBits(bits, (int)lengthAsBits);
            return(bs);
        }
Example #11
0
        public void TestExpressionTreeExceptions()
        {
            Etree = new ExpressionTree("2*3/0");
            double result;

            /**DivideByZeroException*/
            try
            {
                result = Etree.Evaluate();
            }
            catch (DivideByZeroException e)
            {
                DivideByZeroException div = new DivideByZeroException();
                Assert.AreEqual(e, div);
            }


            /**OverflowException*/
            string maxDouble = double.MaxValue.ToString();

            maxDouble += "+1";
            Etree      = new ExpressionTree(maxDouble);
            try
            {
                result = Etree.Evaluate();
            }
            catch (OverflowException e)
            {
                OverflowException div = new OverflowException();
                Assert.AreEqual(e, div);
            }
        }
Example #12
0
    // Returns true if the expected result is right
    // Returns false if the expected result is wrong
    public bool PosTest1()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest1: Create a new instance of OverflowException.");
        try
        {
            string            expectValue       = "HELLO";
            ArgumentException notFoundException = new ArgumentException();
            OverflowException myException       = new OverflowException(expectValue, notFoundException);
            if (myException == null)
            {
                TestLibrary.TestFramework.LogError("001.1", "OverflowException instance can not create correctly.");
                retVal = false;
            }
            if (myException.Message != expectValue)
            {
                TestLibrary.TestFramework.LogError("001.2", "the Message should return " + expectValue);
                retVal = false;
            }
            if (!(myException.InnerException is ArgumentException))
            {
                TestLibrary.TestFramework.LogError("001.3", "the InnerException should return ArgumentException.");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("001.0", "Unexpected exception: " + e);
            retVal = false;
        }
        return(retVal);
    }
        public static EnumValues <TUnderlyingType> GetNamesAndValues <TUnderlyingType>(Type enumType)
            where TUnderlyingType : struct
        {
            if (enumType == null)
            {
                throw new ArgumentNullException("enumType");
            }
            ValidationUtils.ArgumentTypeIsEnum(enumType, "enumType");
            IList <object> values = EnumUtils.GetValues(enumType);
            IList <string> names  = EnumUtils.GetNames(enumType);
            EnumValues <TUnderlyingType> enumValue = new EnumValues <TUnderlyingType>();

            for (int i = 0; i < values.Count; i++)
            {
                try
                {
                    enumValue.Add(new EnumValue <TUnderlyingType>(names[i], (TUnderlyingType)Convert.ChangeType(values[i], typeof(TUnderlyingType), CultureInfo.CurrentCulture)));
                }
                catch (OverflowException overflowException1)
                {
                    OverflowException overflowException = overflowException1;
                    throw new Exception(string.Format(CultureInfo.InvariantCulture, "Value from enum with the underlying type of {0} cannot be added to dictionary with a value type of {1}. Value was too large: {2}", new object[] { Enum.GetUnderlyingType(enumType), typeof(TUnderlyingType), Convert.ToUInt64(values[i], CultureInfo.InvariantCulture) }), overflowException);
                }
            }
            return(enumValue);
        }
Example #14
0
        private static OverflowException _Overflow(string error)
        {
            OverflowException e = new OverflowException(error);

            ExceptionBuilder.TraceExceptionAsReturnValue(e);
            return(e);
        }
Example #15
0
        protected override BitwiseStream InternalValueToBitStream()
        {
            dynamic value = GetNumber(InternalValue);

            if (value > 0 && (ulong)value > MaxValue)
            {
                string msg   = string.Format("Error, {0} value '{1}' is greater than the maximum {2}-bit {3} number.", debugName, value, lengthAsBits, Signed ? "signed" : "unsigned");
                var    inner = new OverflowException(msg);
                throw new SoftException(inner);
            }

            if (value < 0 && (long)value < MinValue)
            {
                string msg   = string.Format("Error, {0} value '{1}' is less than the minimum {2}-bit {3} number.", debugName, value, lengthAsBits, Signed ? "signed" : "unsigned");
                var    inner = new OverflowException(msg);
                throw new SoftException(inner);
            }

            ulong bits = _endian.GetBits(value, (int)lengthAsBits);

            var bs = new BitStream();

            bs.WriteBits(bits, (int)lengthAsBits);
            bs.Seek(0, System.IO.SeekOrigin.Begin);
            return(bs);
        }
        public static void Ctor_String_Exception()
        {
            string message        = "overflow";
            var    innerException = new Exception("Inner exception");
            var    exception      = new OverflowException(message, innerException);

            ExceptionUtility.ValidateExceptionProperties(exception, hResult: COR_E_OVERFLOW, innerException: innerException, message: message);
        }
        public void ConstructorWithMessageWorks()
        {
            var ex = new OverflowException("The message");

            Assert.True((object)ex is OverflowException, "is OverflowException");
            Assert.AreEqual(ex.InnerException, Script.Undefined, "InnerException");
            Assert.AreEqual(ex.Message, "The message");
        }
Example #18
0
        public void WillThrowArgumentException()
        {
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");

            OverflowException exception = Assert.Throws <OverflowException>(() => new UInt24(999999999));

            Assert.That(exception.Message, Is.EqualTo("Value was either too large or too small for an UInt24."));
        }
Example #19
0
        public void TypePropertiesAreCorrect()
        {
            Assert.AreEqual("System.OverflowException", typeof(OverflowException).FullName, "Name");
            object d = new OverflowException();

            Assert.True(d is OverflowException, "is OverflowException");
            Assert.True(d is Exception, "is Exception");
        }
Example #20
0
        public void TypePropertiesAreCorrect()
        {
            Assert.AreEqual("Bridge.OverflowException", typeof(OverflowException).GetClassName(), "Name");
            object d = new OverflowException();

            Assert.True(d is OverflowException, "is OverflowException");
            Assert.True(d is Exception, "is Exception");
        }
Example #21
0
        public void DefaultConstructorWorks()
        {
            var ex = new OverflowException();

            Assert.True((object)ex is OverflowException, "is OverflowException");
            Assert.AreEqual(null, ex.InnerException, "InnerException");
            Assert.AreEqual("Arithmetic operation resulted in an overflow.", ex.Message);
        }
Example #22
0
 public static Exception CreateRethrowableClone(OverflowException ex)
 {
     if (ex == null)
     {
         throw new OverflowRethrowableException("Can only create a clone of an existing exception.");
     }
     return(new OverflowRethrowableException(ex.Message, ex));
 }
Example #23
0
        public void ConstructorWithMessageWorks()
        {
            var ex = new OverflowException("The message");

            Assert.True((object)ex is OverflowException, "is OverflowException");
            Assert.AreEqual(null, ex.InnerException, "InnerException");
            Assert.AreEqual("The message", ex.Message);
        }
Example #24
0
        public void ConstructorWithMessageAndInnerExceptionWorks()
        {
            var inner = new Exception("a");
            var ex    = new OverflowException("The message", inner);

            Assert.True((object)ex is OverflowException, "is OverflowException");
            Assert.True(ReferenceEquals(ex.InnerException, inner), "InnerException");
            Assert.AreEqual("The message", ex.Message);
        }
Example #25
0
        public void ConnectionString_PacketSize_Invalid()
        {
            SqlConnection cn = new SqlConnection();

            // invalid packet size (< minimum)
            try
            {
                cn.ConnectionString = "Packet Size=511";
            }
            catch (ArgumentException ex)
            {
                // Invalid 'Packet Size'.  The value must be an
                // integer >= 512 and <= 32768
                Assert.Equal(typeof(ArgumentException), ex.GetType());
                Assert.Null(ex.InnerException);
                Assert.NotNull(ex.Message);
                Assert.True(ex.Message.IndexOf("'Packet Size'") != -1);
                Assert.Null(ex.ParamName);
            }

            // invalid packet size (> maximum)
            try
            {
                cn.ConnectionString = "packet SIze=32769";
            }
            catch (ArgumentException ex)
            {
                // Invalid 'Packet Size'.  The value must be an
                // integer >= 512 and <= 32768
                Assert.Equal(typeof(ArgumentException), ex.GetType());
                Assert.Null(ex.InnerException);
                Assert.NotNull(ex.Message);
                Assert.True(ex.Message.IndexOf("'Packet Size'") != -1);
                Assert.Null(ex.ParamName);
            }

            // overflow
            try
            {
                cn.ConnectionString = "packet SIze=2147483648";
            }
            catch (ArgumentException ex)
            {
                // Invalid value for key 'packet size'
                Assert.Equal(typeof(ArgumentException), ex.GetType());
                Assert.NotNull(ex.InnerException);
                Assert.Equal(typeof(OverflowException), ex.InnerException.GetType());
                Assert.NotNull(ex.Message);
                Assert.True(ex.Message.IndexOf("'packet size'") != -1);
                Assert.Null(ex.ParamName);

                // Value was either too large or too small for an Int32
                OverflowException oe = (OverflowException)ex.InnerException;
                Assert.Null(oe.InnerException);
                Assert.NotNull(oe.Message);
            }
        }
Example #26
0
        public void ConnectionString_MinPoolSize_Invalid()
        {
            SqlConnection cn = cn = new SqlConnection();

            // negative number
            try {
                cn.ConnectionString = "Min Pool Size=-1";
                Assert.Fail("#A1");
            } catch (ArgumentException ex) {
                // Invalid value for key 'min pool size'
                Assert.AreEqual(typeof(ArgumentException), ex.GetType(), "#A2");
                Assert.IsNull(ex.InnerException, "#A3");
                Assert.IsNotNull(ex.Message, "#A4");
#if NET_2_0
                Assert.IsTrue(ex.Message.IndexOf("'min pool size'") != -1, "#A5:" + ex.Message);
#endif
                Assert.IsNull(ex.ParamName, "#A6");
            }

            // invalid number
            try {
                cn.ConnectionString = "min Pool size=BB";
                Assert.Fail("#B1");
            } catch (ArgumentException ex) {
                // Invalid value for key 'min pool size'
                Assert.AreEqual(typeof(ArgumentException), ex.GetType(), "#B2");
                Assert.IsNotNull(ex.InnerException, "#B3");
                Assert.AreEqual(typeof(FormatException), ex.InnerException.GetType(), "#B4");
                Assert.IsNotNull(ex.Message, "#B5");
                Assert.IsTrue(ex.Message.IndexOf("'min pool size'") != -1, "#B6:" + ex.Message);
                Assert.IsNull(ex.ParamName, "#B7");

                // Input string was not in a correct format
                FormatException fe = (FormatException)ex.InnerException;
                Assert.IsNull(fe.InnerException, "#B8");
                Assert.IsNotNull(fe.Message, "#B9");
            }

            // overflow
            try {
                cn.ConnectionString = "min pool size=2147483648";
                Assert.Fail("#C1");
            } catch (ArgumentException ex) {
                // Invalid value for key 'min pool size'
                Assert.AreEqual(typeof(ArgumentException), ex.GetType(), "#C2");
                Assert.IsNotNull(ex.InnerException, "#C3");
                Assert.AreEqual(typeof(OverflowException), ex.InnerException.GetType(), "#C4");
                Assert.IsNotNull(ex.Message, "#C5");
                Assert.IsTrue(ex.Message.IndexOf("'min pool size'") != -1, "#C6:" + ex.Message);
                Assert.IsNull(ex.ParamName, "#C7");

                // Value was either too large or too small for an Int32
                OverflowException oe = (OverflowException)ex.InnerException;
                Assert.IsNull(oe.InnerException, "#C8");
                Assert.IsNotNull(oe.Message, "#C9");
            }
        }
        public void Add_OverflowException_MessageAndDefaultValue()
        {
            var calc = new Calculator();

            var ex      = new OverflowException();
            var message = ex.Message;
            var actual  = calc.Add("99999999999999999999999999999999999999999999");

            Assert.AreEqual(0, actual, message, ex);
        }
        public void Should_Have_Valid_Latitude_Number_When_Instantiated()
        {
            double            latitude  = double.NaN;
            double            longitude = 0.0;
            OverflowException ex        = Assert.Throws <OverflowException>(
                () => new GeographicLocation(latitude, longitude)
                );

            Assert.Contains(DeploySoftware_LaunchPad_Core_Resources.Guard_GeographicLocation_Set_Latitude_NaN, ex.Message);
        }
Example #29
0
        public void InitBoard_HeightIsNegative_OverflowException()
        {
            //arrange
            Board board    = new Board(1, -1);
            Type  expected = new OverflowException().GetType();

            //act

            //assert
            Assert.Throws <OverflowException>(() => board.InitCells());
        }
Example #30
0
        public void WillThrowArgumentException()
        {
            Int24             int24     = new Int24();
            OverflowException exception = Assert.Throws <OverflowException>(() => int24.Value = 8388608);

            Assert.That(exception.Message, Is.EqualTo("Value was either too large or too small for an Int24."));

            exception = Assert.Throws <OverflowException>(() => int24.Value = -8388609);

            Assert.That(exception.Message, Is.EqualTo("Value was either too large or too small for an Int24."));
        }
Example #31
0
        internal Exception TryToTimeSpan(DurationType durationType, out TimeSpan result)
        {
            Exception exception = null;
            ulong     num       = 0L;

            try
            {
                if (durationType != DurationType.DayTimeDuration)
                {
                    num += (((ulong)this.years) + (((ulong)this.months) / 12L)) * ((ulong)0x16dL);
                    num += (((ulong)this.months) % 12L) * ((ulong)30L);
                }
                if (durationType != DurationType.YearMonthDuration)
                {
                    num += (ulong)this.days;
                    num *= (ulong)0x18L;
                    num += (ulong)this.hours;
                    num *= (ulong)60L;
                    num += (ulong)this.minutes;
                    num *= (ulong)60L;
                    num += (ulong)this.seconds;
                    num *= (ulong)0x989680L;
                    num += ((ulong)this.Nanoseconds) / 100L;
                }
                else
                {
                    num *= (ulong)0xc92a69c000L;
                }
                if (this.IsNegative)
                {
                    if (num == 9223372036854775808L)
                    {
                        result = new TimeSpan(-9223372036854775808L);
                    }
                    else
                    {
                        result = new TimeSpan(0L - ((long)num));
                    }
                }
                else
                {
                    result = new TimeSpan((long)num);
                }
                return(null);
            }
            catch (OverflowException)
            {
                result    = TimeSpan.MinValue;
                exception = new OverflowException(Res.GetString("XmlConvert_Overflow", new object[] { durationType, "TimeSpan" }));
            }
            return(exception);
        }
Example #32
0
        public int TryParse(char *chars, int length, out int value, bool exception = false)
        {
            int r = TryParse(chars, length, out long int64Value, exception);

            if (int64Value > int.MaxValue || int64Value < int.MinValue)
            {
                ThreadException = new OverflowException("Value out of Int32 range.");
            }

            value = (int)int64Value;

            return(r);
        }
 // Returns true if the expected result is right
 // Returns false if the expected result is wrong
 public bool PosTest1()
 {
     bool retVal = true;
     TestLibrary.TestFramework.BeginScenario("PosTest1: Create a new instance of OverflowException.");
     try
     {
         OverflowException myException = new OverflowException();
         if (myException == null)
         {
             TestLibrary.TestFramework.LogError("001.1", "OverflowException instance can not create correctly.");
             retVal = false;
         }
     }
     catch (Exception e)
     {
         TestLibrary.TestFramework.LogError("001.0", "Unexpected exception: " + e);
         retVal = false;
     }
     return retVal;
 }
Example #34
0
 private static OverflowException _Overflow(string error)
 {
     OverflowException e = new OverflowException(error);
     ExceptionBuilder.TraceExceptionAsReturnValue(e);
     return e;
 }
Example #35
0
        static internal Exception ParameterConversionFailed(object value, Type destType, Exception inner)
        {
            Debug.Assert(null != value, "null value on conversion failure");
            Debug.Assert(null != inner, "null inner on conversion failure");

            Exception e;
            string message = Res.GetString(Res.ADP_ParameterConversionFailed, value.GetType().Name, destType.Name);
            if (inner is ArgumentException)
            {
                e = new ArgumentException(message, inner);
            }
            else if (inner is FormatException)
            {
                e = new FormatException(message, inner);
            }
            else if (inner is InvalidCastException)
            {
                e = new InvalidCastException(message, inner);
            }
            else if (inner is OverflowException)
            {
                e = new OverflowException(message, inner);
            }
            else
            {
                e = inner;
            }
            return e;
        }
Example #36
0
 static internal OverflowException Overflow(string error, Exception inner)
 {
     OverflowException e = new OverflowException(error, inner);
     return e;
 }