Solved

Error number in vb.net

Posted on 2003-11-19
5
2,744 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Sorry for late response
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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)…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

13 Experts available now in Live!

Get 1:1 Help Now