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?
}