473,324 Members | 2,239 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,324 software developers and data experts.

How to Fetch the error code

Hi All,

I am writing an simple code like this one

try
{
string abc = "new";

}
catch(Exception ex)
{
if(errorcode == ex.??)

do this;
else
do this;

}

My Question is that i need to fetch the error code using Exception ex so that based on the error code i can display the genric message for the exception. In some articles i have read that we can do this with the help HResult property.

Could any one tell me with a code that how to fetch error code?

Thanks
Nikhil Gupta
Dec 26 '07 #1
1 1064
Plater
7,872 Expert 4TB
The "errorcode" is usually used to determine which exception is thrown (IOException, OutOfMemoryException, IndexOutOfBoundsException, etc)
Which can be trapped in a number of different ways:
Expand|Select|Wrap|Line Numbers
  1. ...
  2. catch (IOException ioe)
  3. {
  4. //do something
  5. }
  6. catch (OutOfMemoryException oome)
  7. {
  8. //do something else
  9. }
  10. catch(Exception ee)
  11. {
  12. //catch anything else
  13. }
  14.  
or
Expand|Select|Wrap|Line Numbers
  1. catch(Exception ee)
  2. {
  3.    if (ee.GetType()==typeof(IOException))
  4.    {
  5.    //do something
  6.    }
  7.    else if (ee.GetType()==typeof(OutOfMemoryException))
  8.    {
  9.    //do something else
  10.    }
  11.    else
  12.    {
  13.    //all the rest
  14.    }
  15. }
  16.  
If you need the actual error number, I think it *might* be contained withen one of the properties.
SocketExceptions however will also have the winsock error code and
Win32Exceptions also have a different number that corrosponds to the specific type of win32 exception.
Dec 26 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Ann | last post by:
Hello everyone, hope someone can help me with this. I have a SQL stored procedure that inserts a record into a table, creates a cursor to fetch the last record that was added to get the unique...
13
by: RR | last post by:
Hi, It appears that DB2 has an arbitrary restriction on the use of "fetch first N rows". I want to insert into a table from a large table query, but only insert the first N rows: insert...
0
by: wingman | last post by:
Hello All I'm completely new to ASP.Net. I need to write a page to fetch an external call which actually call a Java program to download a file, the content of this downloaded is...
9
by: Acupuncture | last post by:
Hi, I am developing a JDBC application and I encountered this problem (DB2 for ISeries). I want to do a select for update and also use the fetch first rows clause. This is my sql statement: ...
0
by: vinidimple | last post by:
Hi i have a serious problem while i was working in Excel.I want to fetch columns from an excel worksheet and i need to compare it with an sql querry fields,so i tried to open an excle...
10
by: scoonie999 | last post by:
I'm having a problem that I can't seem to find any solution for online. I'm using a cursor in a cobol program to fetch some data. I know for a fact that the select should return 2 rows. The...
0
by: reegz | last post by:
Hi guys, I am having trouble executing the following command. Could someone please assist me with a way to get this query working or another way of doing this. INSERT INTO doc_hist (SELECT *...
15
by: dataguy | last post by:
I am trying to insert into a temporary table but only the first n number of rows. I thought I could use the combination of insert into and fect first row command ,but it won't work. Does anyone...
0
by: Rilly | last post by:
Anyone use PowerMovielist here? I have the 0.14 beta version. Do you have a problem where some shows you search for cause the fetch to hang ? I'm pulling my hair out on this.. For example, I search...
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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: 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
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.