• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# System.FormatException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.FormatException的典型用法代码示例。如果您正苦于以下问题:C# FormatException类的具体用法?C# FormatException怎么用?C# FormatException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



FormatException类属于System命名空间,在下文中一共展示了FormatException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: TypePropertiesAreCorrect

		public void TypePropertiesAreCorrect() {
			Assert.AreEqual(typeof(FormatException).FullName, "ss.FormatException", "Name");
			Assert.IsTrue(typeof(FormatException).IsClass, "IsClass");
			Assert.AreEqual(typeof(FormatException).BaseType, typeof(Exception), "BaseType");
			object d = new FormatException();
			Assert.IsTrue(d is FormatException, "is FormatException");
			Assert.IsTrue(d is Exception, "is Exception");

			var interfaces = typeof(FormatException).GetInterfaces();
			Assert.AreEqual(interfaces.Length, 0, "Interfaces length");
		}
开发者ID:ShuntaoChen,项目名称:SaltarelleCompiler,代码行数:11,代码来源:FormatExceptionTests.cs


示例17: ThrowInformativeException

		private static void ThrowInformativeException(string when, string[] formats, FormatException e)
		{
			var builder = new StringBuilder();
			builder.AppendFormat("One of the date fields contained a date/time format which could not be parsed ({0})." + Environment.NewLine, when);
			builder.Append("This program can parse the following formats: ");
			foreach (var format in formats)
			{
				builder.Append(format + Environment.NewLine);
			}
			builder.Append("See: http://en.wikipedia.org/wiki/ISO_8601 for an explanation of these symbols.");
			throw new ApplicationException(builder.ToString(), e);
		}
开发者ID:jwickberg,项目名称:libpalaso,代码行数:12,代码来源:DateTimeExtensions.cs


示例18: GetAliasesFromFile

 private Collection<AliasInfo> GetAliasesFromFile(bool isLiteralPath)
 {
     Collection<AliasInfo> collection = new Collection<AliasInfo>();
     string filePath = null;
     using (StreamReader reader = this.OpenFile(out filePath, isLiteralPath))
     {
         CSVHelper helper = new CSVHelper(',');
         long num = 0L;
         string line = null;
         while ((line = reader.ReadLine()) != null)
         {
             num += 1L;
             if (((line.Length != 0) && !OnlyContainsWhitespace(line)) && (line[0] != '#'))
             {
                 Collection<string> collection2 = helper.ParseCsv(line);
                 if (collection2.Count != 4)
                 {
                     string message = StringUtil.Format(AliasCommandStrings.ImportAliasFileInvalidFormat, filePath, num);
                     FormatException exception = new FormatException(message);
                     ErrorRecord errorRecord = new ErrorRecord(exception, "ImportAliasFileFormatError", ErrorCategory.ReadError, filePath) {
                         ErrorDetails = new ErrorDetails(message)
                     };
                     base.ThrowTerminatingError(errorRecord);
                 }
                 ScopedItemOptions none = ScopedItemOptions.None;
                 try
                 {
                     none = (ScopedItemOptions) Enum.Parse(typeof(ScopedItemOptions), collection2[3], true);
                 }
                 catch (ArgumentException exception2)
                 {
                     string str4 = StringUtil.Format(AliasCommandStrings.ImportAliasOptionsError, filePath, num);
                     ErrorRecord record2 = new ErrorRecord(exception2, "ImportAliasOptionsError", ErrorCategory.ReadError, filePath) {
                         ErrorDetails = new ErrorDetails(str4)
                     };
                     base.WriteError(record2);
                     continue;
                 }
                 AliasInfo item = new AliasInfo(collection2[0], collection2[1], base.Context, none);
                 if (!string.IsNullOrEmpty(collection2[2]))
                 {
                     item.Description = collection2[2];
                 }
                 collection.Add(item);
             }
         }
         reader.Close();
     }
     return collection;
 }
开发者ID:nickchal,项目名称:pash,代码行数:50,代码来源:ImportAliasCommand.cs


示例19: InnerExceptions

 public void InnerExceptions()
 {
     Exception inner = new FormatException();
     ApplicationException outer = new ApplicationException(null, inner);
     JsonObject error = JsonRpcError.FromException(ThrowAndCatch(outer));
     JsonArray errors = (JsonArray) error["errors"];
     Assert.AreEqual(2, errors.Count);
     error = (JsonObject) errors.Shift();
     Assert.AreEqual(outer.Message, error["message"]);
     Assert.AreEqual("ApplicationException", error["name"]);
     error = (JsonObject) errors.Shift();
     Assert.AreEqual(inner.Message, error["message"]);
     Assert.AreEqual("FormatException", error["name"]);
 }
开发者ID:krbvroc1,项目名称:KeeFox,代码行数:14,代码来源:TestJsonRpcError.cs


示例20: TestWhenAll1_Canceled1_Faulted1

        public void TestWhenAll1_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)
                };
            Task delayed = DelayedTask.WhenAll(tasks);
            Assert.IsFalse(delayed.IsCompleted);

            try
            {
                delayed.Wait();
                Assert.Fail("Expected an exception");
            }
            catch (AggregateException ex)
            {
                Assert.AreEqual(TaskStatus.Faulted, delayed.Status);
                Assert.AreEqual(1, ex.InnerExceptions.Count);
                foreach (Exception innerException in ex.InnerExceptions)
                {
                    Assert.AreSame(expectedException, innerException);
                }
            }

            Assert.IsTrue(delayed.IsCompleted);
            Assert.IsTrue(delayed.IsFaulted);
            Assert.AreEqual(TaskStatus.Faulted, delayed.Status);

            Task firstTask = tasks.ElementAt(0);
            Assert.IsTrue(firstTask.IsCompleted);
            Assert.IsTrue(firstTask.IsCanceled);
            Assert.AreEqual(TaskStatus.Canceled, firstTask.Status);

            Task secondTask = tasks.ElementAt(1);
            Assert.IsTrue(secondTask.IsCompleted);
            Assert.IsTrue(secondTask.IsFaulted);
            Assert.AreEqual(TaskStatus.Faulted, secondTask.Status);
            Assert.IsNotNull(secondTask.Exception);
            Assert.AreEqual(1, secondTask.Exception.InnerExceptions.Count);
            Assert.AreSame(expectedException, secondTask.Exception.InnerExceptions[0]);
        }
开发者ID:gitter-badger,项目名称:dotnet-threading,代码行数:49,代码来源:TestDelayedTask_WhenAll.cs



注:本文中的System.FormatException类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# System.Function类代码示例发布时间:2022-05-26
下一篇:
C# System.Form1类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap