HResult property

G

Guest

The exception class has a protected property HResult. If I want to catch a particular exception, I need to know it's HResult and I need to access the HResult.

Every attempt I've made to access it has failed. When I hover my mouse over the code the message is something like "Hresult is not accessible under these circumstances because it is a protected property.

The second problem is that only a few exceptions have a 'name'. It seems amazing to me that in the 4+GB MSDN library, I can't find a listing of Hresults and the errors they correspond to. Either there is a listing and I just can't find it, or Microsoft has been terribly negligent

Can somebody help me on both these matters

polynomial5d
 
A

Alvin Bruney [MVP]

Unless i misunderstood you (in that case please clarify), microsoft .net has
moved away from COM style results. Instead you can only catch exception
objects, not hresults.

Typically, when unmanaged code encounters an error, the result is an HRESULT
type. Managed code converts this hresult into an exception and then throws
it. Consequently, you cannot trap for an hresult error and you cannot access
it directly either. It is available if you extend the exception object. For
obvious reasons, the hresult way of trapping and recording run-time
exceptions is problematic, error prone and not cross language friendly at
best.

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/27cok
polynomial5d said:
The exception class has a protected property HResult. If I want to catch
a particular exception, I need to know it's HResult and I need to access the
HResult.
Every attempt I've made to access it has failed. When I hover my mouse
over the code the message is something like "Hresult is not accessible under
these circumstances because it is a protected property."
The second problem is that only a few exceptions have a 'name'. It seems
amazing to me that in the 4+GB MSDN library, I can't find a listing of
Hresults and the errors they correspond to. Either there is a listing and I
just can't find it, or Microsoft has been terribly negligent.
 
G

Guest

Then I still have the problem of a listing of all exceptions. Nowhere can I find such a list. Furthermore, I know some oledbexceptions don't have a 'name' at all. For example, the duplicate key exception, which I can only identify by its sqlstate = 3022. This seems a step backwards. How can I catch exceptions if I don't know their names, if they have no names, etc

polynomial5d
 
A

Alvin Bruney [MVP]

You may be looking for this
http://msdn.microsoft.com/library/d...n-us/cpguide/html/cpconHRESULTsExceptions.asp

this provides an overview of the architecture
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/exceptdotnet.asp

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/27cok
polynomial5d said:
Then I still have the problem of a listing of all exceptions. Nowhere can
I find such a list. Furthermore, I know some oledbexceptions don't have a
'name' at all. For example, the duplicate key exception, which I can only
identify by its sqlstate = 3022. This seems a step backwards. How can I
catch exceptions if I don't know their names, if they have no names, etc.
 
G

Guest

Thank you very much, Alvin

I added the links to my favorites microsoftarticles/exceptions. It'll take some reading and testing

polynomial5d
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top