帮助理解异常消息 [英] Help in understanding Exception Message

查看:80
本文介绍了帮助理解异常消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为一位已经运行很久的朋友编写了一个Windows窗体应用程序。突然,当他们启动应用程序时出现以下情况,我没有足够的经验去了解哪里可以看到,任何指针都非常感激。



I have coded a windows forms app for a friend which has been running great for ages. All of a sudden when they started the app the following appeared and I'm not experienced enough to understand where to look, any pointers greatly appreciated.

************** Exception Text **************
System.InvalidCastException: Argument 'Number' cannot be converted to a numeric value.
   at Microsoft.VisualBasic.Conversion.Str(Object Number)
   at GtracsX4.gtzModSub.CalculateRegNo(String& r1)
   at GtracsX4.gtzLogin.btn0_Click(Object sender, EventArgs e)
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.PerformClick()
   at GtracsX4.gtzLogin.rb_CheckedChanged(Object sender, EventArgs e)
   at System.Windows.Forms.RadioButton.OnCheckedChanged(EventArgs e)
   at System.Windows.Forms.RadioButton.set_Checked(Boolean value)
   at System.Windows.Forms.RadioButton.OnClick(EventArgs e)
   at System.Windows.Forms.RadioButton.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18444 built by: FX451RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
GtracsX4
    Assembly Version: 1.0.1.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Program%20Files%20(x86)/GtracsX4/GtracsX4.exe
----------------------------------------
System.Drawing
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.34238 built by: FX452RTMGDR
    CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Windows.Forms
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.34251 built by: FX452RTMGDR
    CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
Microsoft.VisualBasic
    Assembly Version: 10.0.0.0
    Win32 Version: 11.0.50938.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.VisualBasic/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System.Core
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System.Data
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_32/System.Data/v4.0_4.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
System.Xml
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.34234 built by: FX452RTMGDR
    CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Configuration
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Data.DataSetExtensions
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/System.Data.DataSetExtensions/v4.0_4.0.0.0__b77a5c561934e089/System.Data.DataSetExtensions.dll
----------------------------------------
System.Numerics
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/System.Numerics/v4.0_4.0.0.0__b77a5c561934e089/System.Numerics.dll
----------------------------------------
System.Transactions
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_32/System.Transactions/v4.0_4.0.0.0__b77a5c561934e089/System.Transactions.dll
----------------------------------------
System.EnterpriseServices
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_32/System.EnterpriseServices/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll
----------------------------------------
Accessibility
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/Accessibility/v4.0_4.0.0.0__b03f5f7f11d50a3a/Accessibility.dll

推荐答案

查看代码,找到相关的行:它在CalculateRegNo方法中,可能是在将参数值转换为数字时。它试图转换的字符串不是有效数字。它期望123或-456.78,并且正在变得你好或类似。



所以使用调试器:在第一行放置一个断点方法,看看数据是什么。然后使用调试器堆栈跟踪返回代码,找出它为什么它是什么!



我们不能为你做到这一点:我们不要我有你的代码,我们没有你的数据...:笑:
Look at your code, and find the relevant line: it's in the CalculateRegNo method, probably when you convert the parameter value to a number. The string it's trying to convert is not a valid number. It expects "123", or "-456.78", and is getting "hello" or similar.

So use the debugger: put a breakpoint on the first line of the method, and look at what the data is. Then use the debugger stack trace to go back through your code to find out why it is whatever it is!

We can't do that for you: we don't have your code, and we don;t have your data... :laugh:


刚看完..



某处 GtracsX4.gtzModSub.CalculateRegNo 它调用 VisualBasic.Conversion.Str

女巫投掷例外,因为 - >它无法将给定参数'Number'Type对象转换为数字类型..



例如 Conversion.Str 无法使用像12a4这样的字符串,因为它不是数字!

Conversion.Str 旨在返回一个字符串表示给定的数值。 (int,short,long,single,double等等。甚至包含有效数字表示的字符串)





但是..为什么不直接使用
Just read..

Somewhere in GtracsX4.gtzModSub.CalculateRegNo it calls VisualBasic.Conversion.Str
witch throws the Exception, because --> it can't convert the given argument 'Number' Type object to a Numeric Type..

For example Conversion.Str can't work with a String like "12a4" because it's not a Number!
Conversion.Str is designed to return a String representing a numeric value given to it. (int, short, long, single, double, etc.. even a string containing a valid numeric representation)


but.. why not just use
value.ToString


这篇关于帮助理解异常消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆