Tag: 例外

System.Runtime.InteropServices.COMException(0x80040154):

我在ac#项目中遇到exception: System.Runtime.InteropServices.COMException(0x80040154):由于以下错误,检索具有CLSID {877AA945-1CB2-411C-ACD7-C70B1F9E2E32}的组件的COM类工厂失败:80040154。 这意味着什么?

Exception hunter有免费的替代方案吗?

我正在Java和C#之间来回切换,而我在C#中编码的一件事就是强制执行的exception检查(尽管我承认在使用Java编写时我也觉得它很烦人)。 我知道Exception Hunter可以帮助你追踪一段代码可能抛出的exception,但是有免费/更便宜的替代方案吗? 我不能为这种软件插件certificate200英镑的合理性,因为它只是一个烦恼而不是一个主要问题。

ArgumentNullException – 如何简化?

我注意到这个代码在我的构造函数中出现了很多: if (someParam == null) throw new ArgumentNullException(“someParam”); if (someOtherParam == null) throw new ArgumentNullException(“someOtherParam”); … 我有一些构造函数,其中注入了几个东西,并且必须都是非null。 谁能想到一种简化这种方法的方法? 我唯一能想到的是以下几点: public static class ExceptionHelpers { public static void CheckAndThrowArgNullEx(IEnumerable<KeyValuePair> parameters) { foreach(var parameter in parameters) if(parameter.Value == null) throw new ArgumentNullException(parameter.Key); } } 但是,使用它会是这样的: ExceptionHelper.CheckAndThrowArgNullEx(new [] { new KeyValuePair(“someParam”, someParam), new KeyValuePair(“someOtherParam”, someOtherParam), … }); …这并没有真正帮助简化代码。 […]

将double转换为十进制时,为什么会出现InvalidCastException

我正在尝试调试获取InvalidCastException的应用程序。 失败的路线是 decimal d = (decimal)row[denominator]; 在调试器中检查这个(见下面的截图),row [denominator]包含一个值为8.0的double,据我所知。 很可能没有任何问题将其转换为小数? (’row’类型来自3. party库 ,它再次来自MySQL的数据。当针对较旧的MySQL服务器进行测试时会出现问题,该服务器显然会在MySQL 5.1上将某些聚合返回为double vs decimal – 同样的查询,完全相同数据库中的数据副本) Visual Studio截图http://img18.imageshack.us/img18/3897/invaldicast.png 有关如何进一步调查此问题的任何帮助?

如何解决:“调用目标引发了exception”C#

C# 每次我运行我的porgram我得到这个例外: 但是当我在调试模式下运行时,没有exception并且程序运行正常,我该怎么办? 注意:我不在项目的任何地方使用invoke() 编辑:好的,这里是详细信息中找到的代码:如果有人知道如何使用protoBuff,并知道这个问题…. ************** Exception Text ************** System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> ProtoBuf.ProtoException: Incorrect wire-type deserializing TimeSpan at ProtoBuf.ProtoBcl.ProtoTimeSpan.DeserializeTicks(SerializationContext context) in c:\protobuf-net_fixed\trunk\protobuf-net\ProtoBcl\ProtoTimeSpan.cs:line 80 at ProtoBuf.ProtoBcl.ProtoTimeSpan.DeserializeDateTime(SerializationContext context) in c:\protobuf-net_fixed\trunk\protobuf-net\ProtoBcl\ProtoTimeSpan.cs:line 41 at ProtoBuf.Property.PropertyDateTimeString`1.DeserializeImpl(TSource source, SerializationContext context) in c:\protobuf-net_fixed\trunk\protobuf-net\Property\PropertyDateTimeString.cs:line 32 at ProtoBuf.Property.Property`2.Deserialize(TSource source, SerializationContext context) in c:\protobuf-net_fixed\trunk\protobuf-net\Property\Property.cs:line 150 at […]

如何使用try-catch获取代码的错误行数

我想得到导致错误的代码行数。 例如; static void Main(string[] args) { using (SqlConnection conn = new SqlConnection(bagcum)) { SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = “DONTINSERT into GIVEMEERROR(CamNo,Statu) values (” + 23 + “,” + 0 + “)”; conn.Open(); int n = cmd.ExecuteNonQuery(); } } 所以我们知道代码不起作用,它会抛出exception行代码,它是: int n = cmd.ExecuteNonQuery(); 那么如何获得使用try-catch行号呢? 我尝试使用StackTrace类,但它将行号设为0: static void Main(string[] args) { try { using […]

如何在C#中获取exception错误代码

try { object result = processClass.InvokeMethod(“Create”, methodArgs); } catch (Exception e) { // Here I was hoping to get an error code. } 当我调用上面的WMI方法时,我应该得到Access Denied。 在我的catch块中,我想确保引发的exception确实是Access Denied。 有没有办法可以得到它的错误代码? Acceess Denied的Win32错误代码是5.我不想在错误消息中搜索拒绝字符串或类似的东西。 谢谢

忽略C#中的exception

有没有更好的方法来忽略C#中的exception,而不是将它放在try catch块中并且在catch中什么都不做? 我发现这种语法很麻烦。 对于代码块,我不能简单地以这种方式“标记”它,以便运行时知道忽略哪些exception?

应用程序代码中的try-catch块无法捕获的exception

MSDN声明,从.NET Framework 2开始, try-catch块无法捕获 StackOverflowException 。 从.NET Framework 2.0版开始,try-catch块无法捕获StackOverflowException对象,并且默认情况下会终止相应的进程。 是否存在相同行为的其他exception?

如何重新抛出InnerException而不会丢失C#中的堆栈跟踪?

我通过反思调用一个可能导致exception的方法。 如何在没有包装器reflection的情况下将exception传递给调用者? 我正在重新抛出InnerException,但这会破坏堆栈跟踪。 示例代码: public void test1() { // Throw an exception for testing purposes throw new ArgumentException(“test1”); } void test2() { try { MethodInfo mi = typeof(Program).GetMethod(“test1”); mi.Invoke(this, null); } catch (TargetInvocationException tiex) { // Throw the new exception throw tiex.InnerException; } }