?
Solved

Error number in vb.net

Posted on 2003-11-19
5
Medium Priority
?
2,820 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 200 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

Docker-Compose to Simplify Multi-Container Builds

Our veteran DevOps Author takes you through how to build a multi-container environment, managed with a single utility in order to simplify your deployments.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

741 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