Solved

Error number in vb.net

Posted on 2003-11-19
5
2,756 Views
Last Modified: 2010-05-18
Hi
I need the .net equiv of Err.Number from vb6.
I can catch all sorts of different error types but I want to know the number.
For example, in asp.net I can catch Err as FileNotFoundException (same as Err.Number=53), but I want to be able to do this:

Try
  ' something
Catch Err as Exception
  If Err.Number = 76 then
     ' hanlde PATH not found error
  end if
  If Err.Number = 53 then
     ' hanlde FILE not found error
  end if
End Try
0
Comment
Question by:jasww
5 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 9779735
AFAIK this isn't possible from the Exception object.  You can resort to the old way from VB6.  VB.NET will support the On Error Goto ErrorHandler type of error handling.  I realize that this is not the preferred method, but sometimes it is the only way.
0
 
LVL 4

Accepted Solution

by:
krznpsk earned 50 total points
ID: 9779979
I believe this is more like what you're trying to do:

 Try
     ' Something
Catch exPathNotFound As System.IO.DirectoryNotFoundException
     ' Handle Path Not Found exception
 Catch exFileNotFound As System.IO.FileNotFoundException
     ' Handle File Not Found exception
 Catch ex As System.Exception
     ' Handle general exception
 End Try
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 9780047
you are approoching this is the wrong way.  You are still thinkling in VB 6 terms.  What is raised is an Exception, of a SPECIFIC type:

so, instead of this:

Catch Err as Exception
  If Err.Number = 76 then
     ' hanlde PATH not found error
  end if
  If Err.Number = 53 then
     ' hanlde FILE not found error
  end if


here is one way to tackle this:

Catch E as FileNotFoundException
           ' hanlde FILE not found exception
Catch E as Exception
      ' an exception OTHER Than FileNotFound occurred
Finally
    'clean up, no matter what
End Try

AW
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 10268184
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: krznpsk {http:#9779979}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

TheLearnedOne
EE Cleanup Volunteer
0
 

Author Comment

by:jasww
ID: 10269722
Sorry for late response
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now