473,806 Members | 2,229 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 8415
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******** ******@TK2MSFTN GP10.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*******@Atre vido.net> wrote in message
news:eZ******** ******@TK2MSFTN GP09.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******** ******@TK2MSFTN GP10.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.Applicat ionException, 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******** ********@TK2MSF TNGP12.phx.gbl. ..
so how do i get a unique error code.
like in vb we had Error.Number

thnx

"Michael Giagnocavo [MVP]" <mg*******@Atre vido.net> wrote in message
news:eZ******** ******@TK2MSFTN GP09.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******** ******@TK2MSFTN GP10.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.co m>
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
16263
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 Server might not be running or the path exists and is redirected to another machine. Please check the status of this virtual directory in the Internet Services Manager."
2
2981
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 unexpected run-time problems. Exceptions on the other hand can not be simply ignored. In order to solve this error codes problem I suggest using error object instead of error codes. Each function has to return an error object that stores an error
13
6621
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
4766
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 appreciated. Thanks in advance
16
2655
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 deciding how to respond. Does anyone know if this is possible.
6
8470
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 by VisitDt" I'm getting this error message: Errno is 2465. Err.description is "Can't find field '|' referred to in your expression"
7
5035
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. I created the websetup and built the MSI, have the bundled version. Copied to webserver and ran Websetup.msi. Said I had to remove old version, which I did, then reran WebSetup.msi and keeps giving me this error. "The installer was interrupted...
4
1905
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
19500
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 will be writing this article intended for those who are in the same level, or maybe lower, of my technical knowledge. I would be using layman's words, or maybe, my own words as how I understand them, hoping, you will understand it the same way that...
0
2897
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 will be writing this article intended for those who are in the same level, or maybe lower, of my technical knowledge. I would be using layman's words, or maybe, my own words as how I understand them, hoping, you will understand it the same way that...
0
9718
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10617
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10364
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10109
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5545
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4328
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.