473,385 Members | 1,353 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Exception - Error Code

When an exception is generated is there not suppose to be a property which
contains the error code? I'm not seeing this property. Does it not show an
error code if the exception comes from a COM component?

Thanks in advance for your assitance.
Jan 25 '06 #1
2 7186
Jim,

No, there isn't a property for the error code, and in reality, you
shouldn't be using such a mechanism, unless the exception represents a fault
in another domain (as in unmanaged code, or COM). In those cases, you will
have a property which will expose that error code. For example,
SocketExceptions return an error code, as do Win32Exceptions and
COMExceptions.

While it is true that ALL exceptions have a protected property which
exposes an HRESULT, this is used for interop situations. Generally though,
you shouldn't use that in code.

You should depend on the type itself to indicate the exception (meaning,
there is a separate type to allow you to differentiate the exceptions) as
well as any information the type exposes.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jim Heavey" <Ji*******@discussions.microsoft.com> wrote in message
news:B7**********************************@microsof t.com...
When an exception is generated is there not suppose to be a property which
contains the error code? I'm not seeing this property. Does it not show
an
error code if the exception comes from a COM component?

Thanks in advance for your assitance.

Jan 25 '06 #2
Yes - but you must have caught a COMException:

try {
// do something
} catch (System.Runtime.InteropServices.COMException ex) { //
COM exception
System.Diagnostics.Debug.WriteLine(ex.GetType().Na me);
System.Diagnostics.Debug.WriteLine(ex.ErrorCode); // HRESULT
throw;
} catch (Exception ex) { // some other exception
System.Diagnostics.Debug.WriteLine(ex.GetType().Na me);
throw;
}

Marc
Jan 25 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Fiona McBride | last post by:
Hi all, I have a really odd problem with some Visual Basic .NET 2003 code; I have a program that creates a number of windows which contain RichTextBox, Timers (disabled) and menus. The code...
1
by: timVerizon | last post by:
Hoping someone can help here.. Our application (C#.Net) was receiving IBM.Data.DB2.DB2Exceptions ERROR SQL0904N Unsuccessful execution caused by an unavailable resource. Reason code: '', type...
5
by: frazer | last post by:
hi i want to get the error code when an error occurs. is catch(Exception ex) { ex.GetHashCode() //will this return a unique number for every error? }
2
by: Janna Deegan | last post by:
Hello all, First off, if there is a better place to post for an answer to this question, please feel free to point me there. I have some very strange behavior happening with my System.web.mail...
6
by: Paul | last post by:
Hello, The following code generates an exception error the *second* time it is called. Can anyone see what I'm doing wrong? There is a similar example in Wrox Professional VB.NET Page 289. ...
9
by: Ron | last post by:
my application is throwing an exception error when closing if I run a procedure in the app. I can't even trap the error with try/catch ex As Exception. Is there a way to completely shut down the...
3
by: dhussong | last post by:
I'm trying to implement a generic exception handling routine that will write information to a text file at the time the exception occurred. I am using the Microsoft Application Block for Exception...
8
by: Philip Colmer | last post by:
I'm rewriting some existing VBScript into VB.Net code. It was all going well until I hit the following error when testing the code: System.Runtime.InteropServices.COMException (0x80041003) at...
11
by: Don | last post by:
When using Visual Basic .NET with a reference to Interop.Outlook, is there a way to get more detailed information about an error other than Exception.Message or Exception.ToString? For example,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.