获得“权利"来自异常的HResult(错误ID) [英] Get "Right" HResult (Error ID) from Exception

查看:508
本文介绍了获得“权利"来自异常的HResult(错误ID)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!.

我是此论坛的新手,所以我不知道此主题是否应在本节中.无论如何,我有一个问题要问专家.


最近,我正在用C#和Java创建自己的SDK.在我的SDK中,我为SDK(C#)创建了一个异常库.

好吧,我要做的是创建自己的错误短语,而不是由Exception类给出的常见错误短语. br>接下来,我做了什么:

Hi!.

I am new in this forum, so I don't know If this thread should be in this section or not. Anyway, I have got one question for experts.


Recently I am creating my own SDK in C# and Java. In my SDK I create an exception library for the SDK (C#).

Well, What I want to do is to create my own error phrases instead the common error phrases given by the Exception classes.

What I did, is the next:

我将代码括在try and pass throw Exception catch中.我发现此异常得到了,并且错误代码(HResult).我认为这段代码是唯一的.因此,我需要做的是获取该代码并将其传递给Exception类的新实例的构造函数.然后,我的异常类将发生该错误,并为该错误返回一个指定短语.但是....当我这样做时,我总是得到HResult = -2146233088,始终是相同的错误代码.我尝试使用不同的Exception错误,但是它总是返回相同的错误代码...为什么?,如何获得每个错误Exception的唯一错误代码.在这里,我传递了一些代码来阐明我要做什么.

.....
I enclose the code in a try and pass throw Exception catch. I spot that this Exception got and Error Code (HResult). I think that this code is unique. So What I need to do , is to get that code and pass it to the constructor of a new instance of my Exception class. Then my exception class, take that error and return an especify phrase for this error.
But.... When I do this, I have always got HResult = -2146233088, always the same error code. I tryed with different Exception errors, but it always returns the same Error code... Why?, How can I get the unique error code for each error Exception. Here I pass some piece of code the clarify What I want to do.

.....

推荐答案

-2146233088,我假设是例外的默认HResult.当您调用"this.HResult"时,这就是您得到的,因为您从未为刚创建的异常指定HRESULT.它不会自动从内部异常继承.您需要调用this.InnerException.HResult(或您所用语言的任何版本).
-2146233088, I assume, is the default HResult for exceptions.  When you call "this.HResult", that is what you get because you never specified the HRESULT for the exception you just created.  Its not automatically inherited from the inner exception.  You need to call this.InnerException.HResult (or whatever your language's version of it is).


这篇关于获得“权利"来自异常的HResult(错误ID)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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