473,320 Members | 1,713 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,320 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 8392
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.