當前位置: 首頁>>代碼示例>>C#>>正文


C# System.FormatException類代碼示例

本文整理匯總了C#中System.FormatException的典型用法代碼示例。如果您正苦於以下問題:C# FormatException類的具體用法?C# FormatException怎麽用?C# FormatException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


FormatException類屬於System命名空間,在下文中一共展示了FormatException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ConstructorWithMessageAndInnerExceptionWorks

		public void ConstructorWithMessageAndInnerExceptionWorks() {
			var inner = new Exception("a");
			var ex = new FormatException("The message", inner);
			Assert.IsTrue((object)ex is FormatException, "is FormatException");
			Assert.IsTrue(ReferenceEquals(ex.InnerException, inner), "InnerException");
			Assert.AreEqual(ex.Message, "The message");
		}
開發者ID:ShuntaoChen,項目名稱:SaltarelleCompiler,代碼行數:7,代碼來源:FormatExceptionTests.cs

示例2: InstantiateException

        public static void InstantiateException()
        {
            int error = 5;
            string message = "This is an error message.";
            Exception innerException = new FormatException();

            // Test each of the constructors and validate the properties of the resulting instance

            Win32Exception ex = new Win32Exception();
            Assert.Equal(expected: E_FAIL, actual: ex.HResult);

            ex = new Win32Exception(error);
            Assert.Equal(expected: E_FAIL, actual: ex.HResult);
            Assert.Equal(expected: error, actual: ex.NativeErrorCode);

            ex = new Win32Exception(message);
            Assert.Equal(expected: E_FAIL, actual: ex.HResult);
            Assert.Equal(expected: message, actual: ex.Message);

            ex = new Win32Exception(error, message);
            Assert.Equal(expected: E_FAIL, actual: ex.HResult);
            Assert.Equal(expected: error, actual: ex.NativeErrorCode);
            Assert.Equal(expected: message, actual: ex.Message);

            ex = new Win32Exception(message, innerException);
            Assert.Equal(expected: E_FAIL, actual: ex.HResult);
            Assert.Equal(expected: message, actual: ex.Message);
            Assert.Same(expected: innerException, actual: ex.InnerException);
        }
開發者ID:Rayislandstyle,項目名稱:corefx,代碼行數:29,代碼來源:Win32Exception.cs

示例3: ConstructorWithMessageWorks

 public void ConstructorWithMessageWorks()
 {
     var ex = new FormatException("The message");
     Assert.True((object)ex is FormatException, "is FormatException");
     Assert.AreEqual(ex.InnerException, null, "InnerException");
     Assert.AreEqual(ex.Message, "The message");
 }
開發者ID:TinkerWorX,項目名稱:Bridge,代碼行數:7,代碼來源:FormatExceptionTests.cs

示例4: DefaultConstructorWorks

 public void DefaultConstructorWorks()
 {
     var ex = new FormatException();
     Assert.True((object)ex is FormatException, "is FormatException");
     Assert.AreEqual(ex.InnerException, null, "InnerException");
     Assert.AreEqual(ex.Message, "Invalid format.");
 }
開發者ID:TinkerWorX,項目名稱:Bridge,代碼行數:7,代碼來源:FormatExceptionTests.cs

示例5: TypePropertiesAreCorrect

 public void TypePropertiesAreCorrect()
 {
     Assert.AreEqual(typeof(FormatException).GetClassName(), "Bridge.FormatException", "Name");
     object d = new FormatException();
     Assert.True(d is FormatException, "is FormatException");
     Assert.True(d is Exception, "is Exception");
 }
開發者ID:TinkerWorX,項目名稱:Bridge,代碼行數:7,代碼來源:FormatExceptionTests.cs

示例6: ConvertFrom

        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            var stringValue = value as string;
            if (stringValue != null)
            {
                var input = stringValue.Trim();

                if (string.IsNullOrEmpty(input))
                {
                    return value;
                }

                // Try to parse. Use the invariant culture instead of the current one.
                TimeSpan timeSpan;
                if (TimeSpan.TryParse(input, CultureInfo.InvariantCulture, out timeSpan))
                {
                    return value;
                }

                var exception = new FormatException(string.Format(CultureInfo.CurrentCulture, Resources.TimeSpanConverter_InvalidString, stringValue));
                throw exception;
            }

            return base.ConvertFrom(context, culture, value);
        }
開發者ID:slamj1,項目名稱:ServiceMatrix,代碼行數:25,代碼來源:InvariantCultureTimeSpanStringConverter.cs

示例7: AddParameter

        internal static string AddParameter (string baseUrl, string parameter, string value)
        {
            // this will get our url's properly formatted
            if (parameter == Constants.UrlParameter.Url)
            {
                try
                {
                    value = new Uri (value).ToString();
                }
                catch (System.FormatException e)  //UriFormatException is not supported in the portable libraries
                {
                    FormatException ufe = new FormatException("Delicious.Net was unable to parse the url \"" + value + "\".\n\n" + e);
                    throw (ufe);
                }
            }
            value = Uri.EscapeDataString(value); //HttpUtility.UrlEncode  is not supported in the portable libraries

            // insert the '?' if needed
            int qLocation = baseUrl.LastIndexOf ('?');
            if (qLocation < 0)
            {
                baseUrl += "?";
                qLocation = baseUrl.Length - 1;
            }

            if (baseUrl.Length > qLocation + 1)
                baseUrl += "&";

            baseUrl += parameter + "=" + value;
            return baseUrl;
        }
開發者ID:jacalata,項目名稱:PortableDelicious.NET,代碼行數:31,代碼來源:Utilities.cs

示例8: TestWhenAny1_Canceled1_Faulted1

        public void TestWhenAny1_Canceled1_Faulted1()
        {
            Exception expectedException = new FormatException();
            Action<Task> exceptionSelector =
                task =>
                {
                    throw expectedException;
                };
            IEnumerable<Task> tasks =
                new[]
                {
                    DelayedTask.Delay(TimeSpan.FromMilliseconds(1 * TimingGranularity.TotalMilliseconds)).Then(_ => CompletedTask.Canceled()),
                    DelayedTask.Delay(TimeSpan.FromMilliseconds(3 * TimingGranularity.TotalMilliseconds)).Select(exceptionSelector).ObserveExceptions()
                };
            Task<Task> delayed = DelayedTask.WhenAny(tasks);
            Assert.IsFalse(delayed.IsCompleted);

            delayed.Wait();
            Assert.IsTrue(delayed.IsCompleted);
            Assert.AreEqual(TaskStatus.RanToCompletion, delayed.Status);
            Assert.IsNotNull(delayed.Result);
            Assert.IsTrue(tasks.Contains(delayed.Result));

            // this one was the first to complete
            Assert.IsTrue(delayed.Result.IsCompleted);
            Assert.IsTrue(delayed.Result.IsCanceled);
            Assert.AreEqual(TaskStatus.Canceled, delayed.Result.Status);
        }
開發者ID:ruanbl,項目名稱:dotnet-threading,代碼行數:28,代碼來源:TestDelayedTask_WhenAny.cs

示例9: DisplayException

 internal static void DisplayException(FormatException exception)
 {
     var title = "Format exception";
     StringBuilder content = new StringBuilder();
     content.AppendLine("There is a problem with the format of the message:");
     content.AppendFormat("Exception: {0}\n\n", exception.Message);
     MessageDialogHelper.ShowDialogAsync(content.ToString(), title);
 }
開發者ID:karayakar,項目名稱:Office-365-REST-API-Explorer,代碼行數:8,代碼來源:MessageDialogHelper.cs

示例10: InvariantWithLambdaMessageAndInnerThrowsCorrectly

 public void InvariantWithLambdaMessageAndInnerThrowsCorrectly()
 {
     FormatException inner = new FormatException();
     Assert.That(() => Check.Invariant(-1, i => i > 0, InvariantMessage, inner),
                 Throws.TypeOf<InvariantException>()
                     .With.Message.ContainsSubstring(InvariantMessage)
                     .And.Property("InnerException").EqualTo(inner));
 }
開發者ID:asbjornu,項目名稱:Sharp-Architecture,代碼行數:8,代碼來源:DesignByContractTests.Invariant.cs

示例11: AssertionWithMessageAndInnerThrowsCorrectly

 public void AssertionWithMessageAndInnerThrowsCorrectly()
 {
     FormatException inner = new FormatException();
     Assert.That(() => Check.Assert(false, AssertionMessage, inner),
                 Throws.TypeOf<AssertionException>()
                     .With.Message.ContainsSubstring(AssertionMessage)
                     .And.Property("InnerException").EqualTo(inner));
 }
開發者ID:asbjornu,項目名稱:Sharp-Architecture,代碼行數:8,代碼來源:DesignByContractTests.Assert.cs

示例12: PostconditionWithLambdaMessageAndInnerThrowsCorrectly

 public void PostconditionWithLambdaMessageAndInnerThrowsCorrectly()
 {
     FormatException inner = new FormatException();
     Assert.That(() => Check.Ensure(-1, i => i > 0, PostconditionMessage, inner),
                 Throws.TypeOf<PostconditionException>()
                     .With.Message.ContainsSubstring(PostconditionMessage)
                     .And.Property("InnerException").EqualTo(inner));
 }
開發者ID:asbjornu,項目名稱:Sharp-Architecture,代碼行數:8,代碼來源:DesignByContractTests.Postcondition.cs

示例13: InputNotANumberLog

 public static void InputNotANumberLog(FormatException e)
 {
     List<string> log = new List<string>();
     log.Add("InputNotANumberError");
     log.Add("Fehlermeldung: " + e.Message);
     log.Add("Fehler bei der Auswahl des Songs.");
     log.Add("Fehlerbehebung: Programm mit Song erneut starten, nur 1, 2 oder 3 eingeben.");
     Errorlogs.PrintLogs(log);
 }
開發者ID:jonatanschneider,項目名稱:CCLI_to_TXT,代碼行數:9,代碼來源:Errorlogs.cs

示例14: ShouldFlattenTheException

            public void ShouldFlattenTheException()
            {
                var formatException = new FormatException("FormatException Message");
                var argumentNullException = new ArgumentNullException("ArgumentNullException Message", formatException);
                var exception = new Exception("Exception Message", argumentNullException);
                var exceptionFlatten = exception.Flatten();

                const string messageExpected = "Exception Message\r\nArgumentNullException Message\r\nFormatException Message\r\n";

                Assert.AreEqual(messageExpected, exceptionFlatten);
            }
開發者ID:justdude,項目名稱:DbExport,代碼行數:11,代碼來源:ExceptionExtensionsTests.cs

示例15: ShouldFindTheSpecifiedException

            public void ShouldFindTheSpecifiedException()
            {
                var formatException = new FormatException();
                var argumentNullException = new ArgumentNullException("", formatException);
                var exception = new Exception("", argumentNullException);

                var foundException = exception.Find<ArgumentNullException>();

                Assert.IsNotNull(foundException);
                Assert.IsInstanceOf(typeof(ArgumentNullException), foundException);
            }
開發者ID:justdude,項目名稱:DbExport,代碼行數:11,代碼來源:ExceptionExtensionsTests.cs


注:本文中的System.FormatException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。