Solved

Error number in vb.net

Posted on 2003-11-19
5
2,768 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

815 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

9 Experts available now in Live!

Get 1:1 Help Now