标签: formatexception

为什么System.Convert("0")在某些系统上抛出FormatException?

该代码在针对.NET3.5的VS2008中编译.这在我的系统上是不可重现的.我怀疑某种本地化设置正在发挥作用,但我对此并不了解.

所有其他有效数字似乎工作正常.该代码说明了该错误(导致相同的异常,但不是生产代码):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = "";
            do
            {
                str = Console.ReadLine();
                Console.WriteLine("\t\"{0}\"", Convert.ToDouble(str));
            }
            while (str != null);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

在命令行,输入"0"会在我遇到的至少一个系统上崩溃应用程序.

来自用户PC的堆栈跟踪:

System.FormatException: Input string was not in a correct format.
   at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   at System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt)
   at System.Double.Parse(String s, NumberStyles style, NumberFormatInfo info)
   at System.Convert.ToDouble(String value)
Run Code Online (Sandbox Code Playgroud)

c# crash formatexception

2
推荐指数
2
解决办法
4994
查看次数

3.5中奇怪的DateTime.Parse异常?

这行代码适用于我的计算机(64位Win7).我在VM中测试了XP 32位.它工作正常.

static bool HasExpire { get { return DateTime.Now >= DateTime.Parse("10/20/2010"); } }
Run Code Online (Sandbox Code Playgroud)

但是在客户端计算机上它会抛出此异常:

在执行当前Web请求期间生成了未处理的异常.可以使用下面的异常堆栈跟踪来识别有关异常的起源和位置的信息.

[FormatException: String was not recognized as a valid DateTime.]
   System.DateTimeParse.Parse(String s,
       DateTimeFormatInfo dtfi,
       DateTimeStyles styles) +2838082
Run Code Online (Sandbox Code Playgroud)

为什么它不能解析客户端计算机上的日期?日期是硬编码的.我不明白这是怎么回事.我确认客户端有3.5,如果我改变该行总是返回false,那么应用程序运行完全正常,除非它无法判断试用期何时到期.

datetime .net-3.5 formatexception

0
推荐指数
1
解决办法
1270
查看次数

C#中的System.FormatException

我继续在我尝试为销售变量分配值的每一个案例中获得FormatException.谁知道我做错了什么?我应该把这个控制台程序作为学习循环的作业,但我发现更多关于其他事情.它应该按照每次销售的10%佣金保持销售人员佣金的运行标签.无论如何,这里是代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TubSales
{
   class Program
   {
      static void Main(string[] args)
      {
         char initial;
         const double COMM_INT = 0.10;
         double sale, aComm = 0, bComm = 0, eComm = 0;
         Console.Write("Enter 'A' for Andrea, 'B' for Brittany,\n'E' for Eric, or 'Z' to quit >> ");
         initial = Convert.ToChar(Console.Read());
         while (initial != 'z' && initial != 'Z')
         {
            switch (initial)
            {
               case 'a':
               case 'A':
                  Console.Write("Enter the sales for Andrea >> ");
                  sale …
Run Code Online (Sandbox Code Playgroud)

c# formatexception

0
推荐指数
1
解决办法
2155
查看次数

处理system.Format Exception C#

在我的应用程序中,我不明白如何处理system.format异常.见下面的代码

public Harvest_Project(XmlNode node)
    {
        this._node = node;
        this._name = node.SelectSingleNode("name").InnerText;

        this._created_at = storeTime(node.SelectSingleNode("created-at").InnerText);
        this._updated_at = storeTime(node.SelectSingleNode("updated-at").InnerText);
        this._over_budget_notified_at = storeTime(node.SelectSingleNode("over-budget-notified-at").InnerText);
        this._latest_record_at = storeTime(node.SelectSingleNode("hint-latest-record-at").InnerText);
        this._earliest_record_at = storeTime(node.SelectSingleNode("hint-earliest-record-at").InnerText);

        this._billable = bool.Parse(node.SelectSingleNode("billable").InnerText);

        try
        {
                this._id = Convert.ToInt32(node.SelectSingleNode("id").InnerText);
                this._client_id = Convert.ToInt32(node.SelectSingleNode("client-id").InnerText);
                this._budget = float.Parse(node.SelectSingleNode("budget").InnerText);
                this._fees = Convert.ToInt32(getXmlNode("fees", node));

        }
        catch (FormatException e)
        {

           Console.WriteLine();
        }
        catch (OverflowException e)
        {
            Console.WriteLine("The number cannot fit in an Int32.");
        }

        this._code = node.SelectSingleNode("code").InnerText;
        this._notes = node.SelectSingleNode("notes").InnerText;

    }
Run Code Online (Sandbox Code Playgroud)

在这里,尝试并捕获块,所有节点都采用int值,但是,因为_fees取"0"值.它显示了格式异常.我只是希望我的节点不显示空字符串.我想处理这个异常.这意味着,它不应该在"this._fees = Convert.ToInt32(getXmlNode("fees",node))"行中抛出异常;" 因为它返回了我想要的int值.

我怎么能实现这一目标?

c# wpf exception-handling formatexception

0
推荐指数
1
解决办法
1069
查看次数

输入字符串的格式不正确:未处理的异常

我想在1个文本框中计算五个文本框的总和....但是当我从五个文本框中保留一个文本框时,它会给出错误输入字符串格式不正确下面是我的代码

        if (textBox6.Text.Length == 0)

        // textBox12.Text = (Convert.ToInt32(textBox5.Text) - Convert.ToInt32(textBox11.Text)).ToString();
        {
            textBox11.Text = (Convert.ToInt32(textBox7.Text) + Convert.ToInt32(textBox8.Text) + Convert.ToInt32(textBox9.Text) + Convert.ToInt32(textBox10.Text)).ToString();
            textBox12.Text = (Convert.ToInt32(textBox5.Text) - Convert.ToInt32(textBox11.Text)).ToString();
        }
        else if (textBox7.Text.Length == 0)
        {
            //textBox11.Text = (Convert.ToInt32(textBox6.Text) + Convert.ToInt32(textBox7.Text) + Convert.ToInt32(textBox8.Text) + Convert.ToInt32(textBox9.Text) + Convert.ToInt32(textBox10.Text)).ToString();
            textBox11.Text = (Convert.ToInt32(textBox6.Text) + Convert.ToInt32(textBox8.Text) + Convert.ToInt32(textBox9.Text) + Convert.ToInt32(textBox10.Text)).ToString();
            textBox12.Text = (Convert.ToInt32(textBox5.Text) - Convert.ToInt32(textBox11.Text)).ToString();
        }
        else if (textBox8.Text.Length == 0)
        {
            //textBox11.Text = (Convert.ToInt32(textBox6.Text) + Convert.ToInt32(textBox7.Text) + Convert.ToInt32(textBox8.Text) + Convert.ToInt32(textBox9.Text) + Convert.ToInt32(textBox10.Text)).ToString();
            textBox11.Text = (Convert.ToInt32(textBox6.Text) + …
Run Code Online (Sandbox Code Playgroud)

c# formatexception

0
推荐指数
1
解决办法
2467
查看次数

获取数字格式的重复

无法解析数字以下.

Long.parseLong("1000.00".length() > 0 ? "1000.00" : "0")
Run Code Online (Sandbox Code Playgroud)

解析"1000.00"然后获取数字格式异常.

如何在java中将"1000.00"这个字符串解析为long?

java string formatexception long-integer

-4
推荐指数
1
解决办法
59
查看次数