当前位置: 首页>>代码示例>>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;未经允许,请勿转载。