Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / December 2004

Tip: Looking for answers? Try searching our database.

Getting the Error Code from the Exception Object

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Vikash Kumar Mitruka - 03 Dec 2004 10:42 GMT
Hi all,

how can i get the unique error code that is associated with each
Exception.

there is one Property of Exception class named HResult. but that is
protected so i can not access it.

How can i do that. if anybody is having any idea than please do inform

Thanks
Vikash
John Saunders - 03 Dec 2004 14:51 GMT
> Hi all,
>
[quoted text clipped - 8 lines]
> Thanks
> Vikash

Vikash, not all exceptions have a unique error code associated with them.
HResult is not useful in the general case.

John Saunders
Stuart Celarier - 04 Dec 2004 01:25 GMT
John wrote:
>HResult is not useful in the general case.

To elaborate a bit, nearly all COM methods return an HRESULT and this is
the basis for COM error handling. Some common HRESULT values are here
[1]. For a more complete list, check out the winerror.h include file
that is normally included by a C++ COM project. COM objects are also
allowed to create custom HRESULT values.

When managed code calls into some COM code, it may get back a failing
HRESULT value. If the managed code can't handle the error, then it would
probably wrap the HRESULT up in a .NET exception and throw it. So for
the HResult value in an exception to be much value you'd probably need
to know what the managed code was doing, and what method on what COM
object was being called. Okay, unless it is something truly obvious like
E_OUTOFMEMORY.

And if the error didn't originate in a COM call, then the HResult is
going to be meaningless.

So what is the bigger problem that you're trying to solve?

Cheers,
Stuart

[1] http://msdn.microsoft.com/library/en-us/com/htm/error_899v.asp

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.