Solved

Error number in vb.net

Posted on 2003-11-19
5
2,796 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

691 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