473,775 Members | 2,611 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get the Exception number

RSB
Hi Every one,
i am using the try Catch block..
and the Exception object has a Message Property but i want to Catch the
Error Number so that based on the Error number i can display Different error
message....

try{

}

Catch (Exception ex)
{
errNum = ex.?????
if (errNum == x) {
do x
}
else if ( errNum == y) {
do y
}
}
so how do i find the Error Number here..

Thanks
RSB
Jul 21 '05 #1
7 2162
RSB <rs*****@hotmai l.com> wrote:
i am using the try Catch block..
and the Exception object has a Message Property but i want to Catch the
Error Number so that based on the Error number i can display Different error
message....

try{

}

Catch (Exception ex)
{
errNum = ex.?????
if (errNum == x) {
do x
}
else if ( errNum == y) {
do y
}
}
so how do i find the Error Number here..


Exception.HResu lt may be what you're after. Can you definitely not
achieve this by catching different types of exception though? That's
the usual practice.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2
Hi,

There is no such beast (take a look at the Exception base class, at its
property and method... if it is not there, ... it is not there).

You should use the Exception derived class, from the particular to the
most general:

catch(ArgumentO utOfRangeExcept ion ex)
{
...
}
catch( ArgumentExcepti on ex)
{
...
}
catch (SystemExceptio n ex)
{
...
}

and so on.

You can "parse" the Exception.Messa ge, or read the
Exception.Inner Exception, or StackTrace, etc. to get more info about the
nature of the error, but a try-catch is, by nature, a termination model, not
a resumption model of error handling... you loose the context, the
environment of the error, since the try scope is done, finish, out, dead.

You can throw a new exception, with a new message, of with a message
based on the existing message.

Hoping it may help,
Vanderghast, Access MVP
"RSB" <rs*****@hotmai l.com> wrote in message
news:U2******** *********@news. cpqcorp.net...
Hi Every one,
i am using the try Catch block..
and the Exception object has a Message Property but i want to Catch the
Error Number so that based on the Error number i can display Different error message....

try{

}

Catch (Exception ex)
{
errNum = ex.?????
if (errNum == x) {
do x
}
else if ( errNum == y) {
do y
}
}
so how do i find the Error Number here..

Thanks
RSB

Jul 21 '05 #3
RSB
Thanks Jon and Michel
that helps me..

"Michel Walsh" <vanderghast@Vi rusAreFunnierTh anSpam> wrote in message
news:ek******** ******@TK2MSFTN GP11.phx.gbl...
Hi,

There is no such beast (take a look at the Exception base class, at its property and method... if it is not there, ... it is not there).

You should use the Exception derived class, from the particular to the
most general:

catch(ArgumentO utOfRangeExcept ion ex)
{
...
}
catch( ArgumentExcepti on ex)
{
...
}
catch (SystemExceptio n ex)
{
...
}

and so on.

You can "parse" the Exception.Messa ge, or read the
Exception.Inner Exception, or StackTrace, etc. to get more info about the
nature of the error, but a try-catch is, by nature, a termination model, not a resumption model of error handling... you loose the context, the
environment of the error, since the try scope is done, finish, out, dead.

You can throw a new exception, with a new message, of with a message
based on the existing message.

Hoping it may help,
Vanderghast, Access MVP
"RSB" <rs*****@hotmai l.com> wrote in message
news:U2******** *********@news. cpqcorp.net...
Hi Every one,
i am using the try Catch block..
and the Exception object has a Message Property but i want to Catch the
Error Number so that based on the Error number i can display Different

error
message....

try{

}

Catch (Exception ex)
{
errNum = ex.?????
if (errNum == x) {
do x
}
else if ( errNum == y) {
do y
}
}
so how do i find the Error Number here..

Thanks
RSB


Jul 21 '05 #4
RSB
So how do i cappture..
Object reference not set to an instance of an object.
i mean what type of Exception i catch there.

thanks

"Michel Walsh" <vanderghast@Vi rusAreFunnierTh anSpam> wrote in message
news:ek******** ******@TK2MSFTN GP11.phx.gbl...
Hi,

There is no such beast (take a look at the Exception base class, at its property and method... if it is not there, ... it is not there).

You should use the Exception derived class, from the particular to the
most general:

catch(ArgumentO utOfRangeExcept ion ex)
{
...
}
catch( ArgumentExcepti on ex)
{
...
}
catch (SystemExceptio n ex)
{
...
}

and so on.

You can "parse" the Exception.Messa ge, or read the
Exception.Inner Exception, or StackTrace, etc. to get more info about the
nature of the error, but a try-catch is, by nature, a termination model, not a resumption model of error handling... you loose the context, the
environment of the error, since the try scope is done, finish, out, dead.

You can throw a new exception, with a new message, of with a message
based on the existing message.

Hoping it may help,
Vanderghast, Access MVP
"RSB" <rs*****@hotmai l.com> wrote in message
news:U2******** *********@news. cpqcorp.net...
Hi Every one,
i am using the try Catch block..
and the Exception object has a Message Property but i want to Catch the
Error Number so that based on the Error number i can display Different

error
message....

try{

}

Catch (Exception ex)
{
errNum = ex.?????
if (errNum == x) {
do x
}
else if ( errNum == y) {
do y
}
}
so how do i find the Error Number here..

Thanks
RSB


Jul 21 '05 #5
RSB,

If you are trying to detect when a variable is set to null, and a
property/method/field is trying to be accessed, then look for the
NullReferenceEx ception.

Hope this helps.

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

"RSB" <rs*****@hotmai l.com> wrote in message
news:JO******** *********@news. cpqcorp.net...
So how do i cappture..
Object reference not set to an instance of an object.
i mean what type of Exception i catch there.

thanks

"Michel Walsh" <vanderghast@Vi rusAreFunnierTh anSpam> wrote in message
news:ek******** ******@TK2MSFTN GP11.phx.gbl...
Hi,

There is no such beast (take a look at the Exception base class, at

its
property and method... if it is not there, ... it is not there).

You should use the Exception derived class, from the particular to
the
most general:

catch(ArgumentO utOfRangeExcept ion ex)
{
...
}
catch( ArgumentExcepti on ex)
{
...
}
catch (SystemExceptio n ex)
{
...
}

and so on.

You can "parse" the Exception.Messa ge, or read the
Exception.Inner Exception, or StackTrace, etc. to get more info about the
nature of the error, but a try-catch is, by nature, a termination model,

not
a resumption model of error handling... you loose the context, the
environment of the error, since the try scope is done, finish, out, dead.

You can throw a new exception, with a new message, of with a message
based on the existing message.

Hoping it may help,
Vanderghast, Access MVP
"RSB" <rs*****@hotmai l.com> wrote in message
news:U2******** *********@news. cpqcorp.net...
> Hi Every one,
> i am using the try Catch block..
> and the Exception object has a Message Property but i want to Catch the
> Error Number so that based on the Error number i can display Different

error
> message....
>
> try{
>
> }
>
> Catch (Exception ex)
> {
> errNum = ex.?????
> if (errNum == x) {
> do x
> }
> else if ( errNum == y) {
> do y
> }
> }
>
>
> so how do i find the Error Number here..
>
> Thanks
> RSB
>
>



Jul 21 '05 #6
Hi,
Sounds to me to be a System.NullRefe reneException. At least, the
following code does:

try
{
string a = null;
int i = a.Length;
}
catch(NullRefer enceException ex)
{
return;
}
catch(Exception ex)
{
return;
}
Place a stop point at each return, start a debug session. If you got
stop at the right return, no problem, you have the intended exception, else,
the catch(Exception ex) should display, in the Locals view, under variable
ex, the exception class you are looking for. Not very high tech, I admit my
culpability...
Hoping it may help
Vanderghast, Access MVP
"RSB" <rs*****@hotmai l.com> wrote in message
news:JO******** *********@news. cpqcorp.net...
So how do i cappture..
Object reference not set to an instance of an object.
i mean what type of Exception i catch there.

thanks

"Michel Walsh" <vanderghast@Vi rusAreFunnierTh anSpam> wrote in message
news:ek******** ******@TK2MSFTN GP11.phx.gbl...
Hi,

There is no such beast (take a look at the Exception base class, at

its
property and method... if it is not there, ... it is not there).

You should use the Exception derived class, from the particular to the most general:

catch(ArgumentO utOfRangeExcept ion ex)
{
...
}
catch( ArgumentExcepti on ex)
{
...
}
catch (SystemExceptio n ex)
{
...
}

and so on.

You can "parse" the Exception.Messa ge, or read the
Exception.Inner Exception, or StackTrace, etc. to get more info about the nature of the error, but a try-catch is, by nature, a termination model,

not
a resumption model of error handling... you loose the context, the
environment of the error, since the try scope is done, finish, out, dead.
You can throw a new exception, with a new message, of with a message
based on the existing message.

Hoping it may help,
Vanderghast, Access MVP
"RSB" <rs*****@hotmai l.com> wrote in message
news:U2******** *********@news. cpqcorp.net...
Hi Every one,
i am using the try Catch block..
and the Exception object has a Message Property but i want to Catch the Error Number so that based on the Error number i can display Different

error
message....

try{

}

Catch (Exception ex)
{
errNum = ex.?????
if (errNum == x) {
do x
}
else if ( errNum == y) {
do y
}
}
so how do i find the Error Number here..

Thanks
RSB



Jul 21 '05 #7
RSB <rs*****@hotmai l.com> wrote:
So how do i cappture..
Object reference not set to an instance of an object.
i mean what type of Exception i catch there.


NullReferenceEx ception.

(If you can get to the message, surely you can also see what type of
exception you've got, can't you?)

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

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

Similar topics

4
15839
by: maricel | last post by:
I have the following base table structure - DDL: CREATE TABLE "ADMINISTRATOR"."T1" ( "C1" INTEGER NOT NULL ) IN "TEST_TS" ; ALTER TABLE "ADMINISTRATOR"."T1" ADD PRIMARY KEY
5
2571
by: juergen perlinger | last post by:
Hello out there. sometimes I need to have proper control of the floating point arithmetic of the C(and C++) runtime system, and using the f.p. exception handling of the C99 standard is quite handy for that purpose. The only problem when dealing with f.p. exception signals is that there is (afaik) no specification *when* the f.p. exception is raised, with one notable exception: 'feraiseexcept(int)' raises the exceptions passed in the...
7
38505
by: RSB | last post by:
Hi Every one, i am using the try Catch block.. and the Exception object has a Message Property but i want to Catch the Error Number so that based on the Error number i can display Different error message.... try{ }
40
13535
by: Kevin Yu | last post by:
is it a bad programming design to throw exception in the try block then catch it??
2
2555
by: £ukasz | last post by:
Hi, I'm writing application which is drawing an icon. Then it's displayed in tray by NotifyIcon. And there is a problem, because sometimes an exception is thrown: Type: System.Runtime.InteropServices.ExternalException Message: A generic error occurred in GDI+.
2
1907
by: André Nogueira | last post by:
Hi there! I am developing an Windows Explorer-like application that will tell you the size of any folder. But so far I have come across some problems. For instance, you may not have access to all folders in NTFS drives, or a floppy disk may not be in the drive when I access it. The question is, how can I check in a Try Catch statement the precise error that was returned? Isn't there an error number? I could check the ex.Message but I...
2
1202
by: Torben Laursen | last post by:
I handle errors in my code by using my own exception class that takes a number as argument to the constructor, and that number puts a string into the exception class. The user can then catch the class and display the string to the user. Now the strings are all stored inside a map inside the exception class. But my number of strings are growing and having them all inside the exception class seems as a bad idear. Does anyone know a good...
2
4955
by: Richard Collette | last post by:
Hi, I have a service, that runs perfectly when executed outside of the web service environment. When called as a web service I get the exception listed below sporadically. A call to the web method may succeed one time and not another. I cannot find any reason why it would work one time and not another. The exception occurs every two or three calls to the web method. The service utilizes a COM component provided by PeopleSoft...
4
2109
by: Ed Dana | last post by:
I am attempting to use exception handling in the console to trap an invalid character into a numeric field. Unfortunately, using this example: ====================================================================== #include <exception> #include <iostream> using namespace std; int main(int argc, char *argv) { double number = 0;
0
9622
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
10268
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...
1
10048
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,...
1
7464
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
6718
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
5360
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...
0
5486
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4017
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
3611
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.