473,386 Members | 1,766 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,386 software developers and data experts.

error code

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?
}
Nov 16 '05 #1
5 8394
Currently, GetHashCode will return a unique "object id" -- per instance.
However this is not guaranteed for future versions, AFAIK.

-Michael

"frazer" <ic***@hotmail.com> wrote in message
news:eZ**************@TK2MSFTNGP10.phx.gbl...
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?
}


Nov 16 '05 #2
so how do i get a unique error code.
like in vb we had Error.Number

thnx

"Michael Giagnocavo [MVP]" <mg*******@Atrevido.net> wrote in message
news:eZ**************@TK2MSFTNGP09.phx.gbl...
Currently, GetHashCode will return a unique "object id" -- per instance.
However this is not guaranteed for future versions, AFAIK.

-Michael

"frazer" <ic***@hotmail.com> wrote in message
news:eZ**************@TK2MSFTNGP10.phx.gbl...
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?
}

Nov 16 '05 #3
frazer wrote:
so how do i get a unique error code.
like in vb we had Error.Number


Do it yourself ;-)

Derive your own Exception class from System.ApplicationException, add an
"ErrorCode" property and some look-up scheme that associates error codes
with messages.

Cheers,

--
Joerg Jooss
jo*********@gmx.net

Nov 16 '05 #4
You can define your own object and add an error code field, but this really
ought not to be used for most scenarios. The preferred way in C# is to throw
and catch specific exception types and take actions based on the exception
type, not on a numeric value within the object. It's not that it cannot be
done, but in most cases it should not be done.

If you are approaching this from the perspective of dealing with exceptions
thrown by other code then you should use the exception type to determine how
to handle the error. From the perspective of writing code that throws
exceptions, you should throw an exception that most specifically indicates
the nature of the problem. If you expect a caller to be able to take
programmatic action based on the exception type, and none of the predefined
types is suitable, then you can define your own exception type and throw
that. If there's no programmatic action that can be taken then you can throw
one of the base exception types.

Dave
"frazer" <ic***@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
so how do i get a unique error code.
like in vb we had Error.Number

thnx

"Michael Giagnocavo [MVP]" <mg*******@Atrevido.net> wrote in message
news:eZ**************@TK2MSFTNGP09.phx.gbl...
Currently, GetHashCode will return a unique "object id" -- per instance.
However this is not guaranteed for future versions, AFAIK.

-Michael

"frazer" <ic***@hotmail.com> wrote in message
news:eZ**************@TK2MSFTNGP10.phx.gbl...
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?
}


Nov 16 '05 #5
frazer <ic***@hotmail.com> wrote:
i want to get the error code when an error occurs.


What error code? If you mean a Windows error code, there may well not
be one associated with the exception which has been thrown.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6

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

Similar topics

5
by: Tony Wright | last post by:
Hi, I am having a problem installing an msi for a web site. The error message I am getting is: "The specified path 'http://mipdev05/features/Fas2' is unavailable. The Internet Information...
2
by: Gregory | last post by:
Hi, One of the disadvantages of using error handling with error codes instead of exception handling is that error codes retuned from a function can be forgotten to check thus leading to...
13
by: deko | last post by:
I use this convention frequently: Exit_Here: Exit Sub HandleErr: Select Case Err.Number Case 3163 Resume Next Case 3376 Resume Next
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
16
by: Steve Jorgensen | last post by:
I'm trying to figure out if there is a way to generate standard error handlers that "know" if the calling code has an error handler in effect (On Error Goto <label> or On Error Resume Next) before...
6
by: Squirrel | last post by:
I have a command button on a subform to delete a record. The only statement in the subroutine is: DoCmd.RunCommand acCmdDeleteRecord The subform's recordsource is "select * from tblVisit order...
7
by: p | last post by:
WE had a Crystal 8 WebApp using vs 2002 which we upgraded to VS2003. I also have Crystal 9 pro on my development machine. The web app runs fine on my dev machine but am having problems deploying....
4
by: Eugene Anthony | last post by:
One problem with the code bellow is after this code conn.qDupUser p1,rs I added: set rs = nothing to test the error handling capability.
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.