473,666 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Get Error Number

RP
If an exception occurs, how to get the error number. I mean, is there
anything like ex.number?

Oct 10 '07 #1
11 4774
On Oct 10, 2:04 pm, RP <rpk.gene...@gm ail.comwrote:
If an exception occurs, how to get the error number. I mean, is there
anything like ex.number?
Hi RP,
There really isn't anything equivalent to an error number in .NET --
typically the type of the exception object thrown is what is used to
do runtime error handling. And the message in the exception is
typically what is shown to the user, not a number. There are some
types of exceptions that have error numbers (see
COMException.Er rorCode) but I think in the new .NET world, the error
number has gone by the wayside.

Is there a particular case where you need to get at the error number
(a la GetLastError from the Win32 days)?

John

Oct 10 '07 #2
RP <rp*********@gm ail.comwrote:
If an exception occurs, how to get the error number. I mean, is there
anything like ex.number?
For many exceptions there *isn't* an error number - after all, you can
create whatever exception you want and throw it.

You can use Exception.HResu lt in some cases, but don't rely on it
always being present.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Oct 10 '07 #3
Hi,

"RP" <rp*********@gm ail.comwrote in message
news:11******** **************@ 19g2000hsx.goog legroups.com...
If an exception occurs, how to get the error number. I mean, is there
anything like ex.number?
Not really, you can get the message of the exception and even the stacktrace
that indicate in which method the exception was thrown.

Oct 10 '07 #4
"Jon Skeet [C# MVP]" <sk***@pobox.co mwrote in message
news:MP******** *************@m snews.microsoft .com...
RP <rp*********@gm ail.comwrote:
>If an exception occurs, how to get the error number. I mean, is there
anything like ex.number?

For many exceptions there *isn't* an error number - after all, you can
create whatever exception you want and throw it.
heh. Perfectly valid, if not quite correct, code...

Object errorNumber = (object) 101;
throw errorNumber;

One day I'm going to figure out why any arbitrary thing can be thrown,
rather than constraining it to only Exceptions...

--
Chris Mullins
Oct 10 '07 #5
Actually, it's not valid C# code. While the CLR does allow for objects
to be thrown, in C#, the compiler requires that the target of the throw
statement derive from System.Exceptio n.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Chris Mullins [MVP - C#]" <cm******@yahoo .comwrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
"Jon Skeet [C# MVP]" <sk***@pobox.co mwrote in message
news:MP******** *************@m snews.microsoft .com...
>RP <rp*********@gm ail.comwrote:
>>If an exception occurs, how to get the error number. I mean, is there
anything like ex.number?

For many exceptions there *isn't* an error number - after all, you can
create whatever exception you want and throw it.

heh. Perfectly valid, if not quite correct, code...

Object errorNumber = (object) 101;
throw errorNumber;

One day I'm going to figure out why any arbitrary thing can be thrown,
rather than constraining it to only Exceptions...

--
Chris Mullins


Oct 10 '07 #6
RP
In VB.NET we have err.Number.

Oct 10 '07 #7
According to Michaelis, "In C# 2.0, all exceptions, whether deriving from
System.Exceptio n or not, will propagate into C# assemblies as derived from
System.Exceptio n. .... the CIL code corresponding to an empty catch block is,
in fact, a catch(object) block..."
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com

"Nicholas Paldino [.NET/C# MVP]" wrote:
Actually, it's not valid C# code. While the CLR does allow for objects
to be thrown, in C#, the compiler requires that the target of the throw
statement derive from System.Exceptio n.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Chris Mullins [MVP - C#]" <cm******@yahoo .comwrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
"Jon Skeet [C# MVP]" <sk***@pobox.co mwrote in message
news:MP******** *************@m snews.microsoft .com...
RP <rp*********@gm ail.comwrote:
If an exception occurs, how to get the error number. I mean, is there
anything like ex.number?

For many exceptions there *isn't* an error number - after all, you can
create whatever exception you want and throw it.
heh. Perfectly valid, if not quite correct, code...

Object errorNumber = (object) 101;
throw errorNumber;

One day I'm going to figure out why any arbitrary thing can be thrown,
rather than constraining it to only Exceptions...

--
Chris Mullins


Oct 10 '07 #8
Which is correct, but it doesn't validate Chris's post, which indicates
that you can actually throw something in C# which does not derive from
Exception.

You could do this in C++/CLI or in IL, but not in C#. And yes, you can
catch it with the catch block which doesn't have an exception argument.

I actually did some of the review work on that book, and know Mark, so I
know exactly which section you are referring to. =)

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Peter Bromberg [C# MVP]" <pb*******@yaho o.yohohhoandabo ttleofrum.comwr ote
in message news:51******** *************** ***********@mic rosoft.com...
According to Michaelis, "In C# 2.0, all exceptions, whether deriving from
System.Exceptio n or not, will propagate into C# assemblies as derived from
System.Exceptio n. .... the CIL code corresponding to an empty catch block
is,
in fact, a catch(object) block..."
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com

"Nicholas Paldino [.NET/C# MVP]" wrote:
> Actually, it's not valid C# code. While the CLR does allow for
objects
to be thrown, in C#, the compiler requires that the target of the throw
statement derive from System.Exceptio n.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Chris Mullins [MVP - C#]" <cm******@yahoo .comwrote in message
news:%2******* *********@TK2MS FTNGP02.phx.gbl ...
"Jon Skeet [C# MVP]" <sk***@pobox.co mwrote in message
news:MP******** *************@m snews.microsoft .com...
RP <rp*********@gm ail.comwrote:
If an exception occurs, how to get the error number. I mean, is there
anything like ex.number?

For many exceptions there *isn't* an error number - after all, you can
create whatever exception you want and throw it.

heh. Perfectly valid, if not quite correct, code...

Object errorNumber = (object) 101;
throw errorNumber;

One day I'm going to figure out why any arbitrary thing can be thrown,
rather than constraining it to only Exceptions...

--
Chris Mullins




Oct 10 '07 #9
Yep, you are correct -- in C# 2.0 Chris's example code is not valid - you
would get "type object does not extend System.Exceptio n" in Intellisense, and
a similar compiler error.

-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com

"Nicholas Paldino [.NET/C# MVP]" wrote:
Which is correct, but it doesn't validate Chris's post, which indicates
that you can actually throw something in C# which does not derive from
Exception.

You could do this in C++/CLI or in IL, but not in C#. And yes, you can
catch it with the catch block which doesn't have an exception argument.

I actually did some of the review work on that book, and know Mark, so I
know exactly which section you are referring to. =)

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Peter Bromberg [C# MVP]" <pb*******@yaho o.yohohhoandabo ttleofrum.comwr ote
in message news:51******** *************** ***********@mic rosoft.com...
According to Michaelis, "In C# 2.0, all exceptions, whether deriving from
System.Exceptio n or not, will propagate into C# assemblies as derived from
System.Exceptio n. .... the CIL code corresponding to an empty catch block
is,
in fact, a catch(object) block..."
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com

"Nicholas Paldino [.NET/C# MVP]" wrote:
Actually, it's not valid C# code. While the CLR does allow for
objects
to be thrown, in C#, the compiler requires that the target of the throw
statement derive from System.Exceptio n.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Chris Mullins [MVP - C#]" <cm******@yahoo .comwrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
"Jon Skeet [C# MVP]" <sk***@pobox.co mwrote in message
news:MP******** *************@m snews.microsoft .com...
RP <rp*********@gm ail.comwrote:
If an exception occurs, how to get the error number. I mean, is there
anything like ex.number?

For many exceptions there *isn't* an error number - after all, you can
create whatever exception you want and throw it.

heh. Perfectly valid, if not quite correct, code...

Object errorNumber = (object) 101;
throw errorNumber;

One day I'm going to figure out why any arbitrary thing can be thrown,
rather than constraining it to only Exceptions...

--
Chris Mullins




Oct 10 '07 #10

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

Similar topics

0
15166
by: Mark Depenbrock | last post by:
--Apple-Mail-2--68472726 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed Can not make mysql connection - error log: 030708 08:53:48 mysqld started
9
2615
by: Mark Twombley | last post by:
Hi, I'm just getting back into C++ and had a question about the best practice for assigning error numbers. I have been working in VB for sometime now and there you would start assigning error number at vbObjectError + count. Is there a similar practice in C++ or is it just coder preference. Thanks -- Mark Twombley
1
3995
by: dawatson833 | last post by:
I want to set an alert for a specific table whenever an event has caused a deadlock to occur on the table. I understand how to set up an alert. But I don't know which error number to use for the New Alert error number property for a deadlock. Or how to specify a deadlock on a specific table. Thanks, DW
1
1454
by: sunil | last post by:
hello folks, Is there a way to get the error number in VB.net Exception class as it was there in VB6 like 'vb code if err.Number=1234 then 'some code here end if
4
2389
by: amywolfie | last post by:
Hi All: In FileMaker Pro, the error number for "no records found" is 401. What is the equivalent error number in Access (2003)? I want to capture for the "On Open" Event of a report. If there are no records found, then return to the Switchboard and close the report. Thanks!
2
3518
by: dixie | last post by:
Can someone please give me the error number for this error? dixie
2
1700
by: Dixie | last post by:
I have an Access Error "Permission Denied" which is generated when I try to delete a folder with a locked file inside. Can anyone tell me the error number for this error? dixie
0
1372
by: alex21 | last post by:
I'm trying to detect the http status number such as (401 Unauthorized) from a 'WebException' when a WebClient in my code fails. Public Function DataSources_ValidURL() As Boolean Dim TestClient As New WebClient() TestClient.BaseAddress = DataSources_FilePath Try TestClient.DownloadString(DataSources_FilePath) Catch ex As WebException If ex.Status = 401 Then ...
6
2050
doma23
by: doma23 | last post by:
Error number: -214217887 Description: Das Feld ist zu klein fur die Datenmenge, die Sie hinzufungen wollten. Versuchen Sie, weniger Daten einzufugen. Hi, I've made a particular tool by using Access 2003. With all the computers in my office everything works fine. I've started testing phase with a colleague in Germany that will need to use the tool as well. However, when she tries to save some data by clicking on SAVE button, she keeps...
0
8445
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
8781
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...
1
8551
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8640
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...
1
6198
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
5664
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
4198
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
2771
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
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.