473,378 Members | 1,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Working with exceptions...

Okay, so this borrowed code is for doing a recursive file search. The
problem is when I encounter the System Volume Information folder, a special
kind of exception is thrown that ends up terminating the subroutine. I have
two other exceptions that are thrown before the one I described does, yet
they don't terminate the subroutine.

Can anyone tell me why one kind of exception terminates this subroutine,
while another does not?

Sub FileSearch(ByVal sDir As String, ByVal FileName As String)
Dim Trigger As Integer = 0
Dim d2 As String
Dim f2 As String
If Trigger = 0 Then
Try
For Each d2 In Directory.GetDirectories(sDir)
For Each f2 In Directory.GetFiles(d2, FileName)
MsgBox(f2, MsgBoxStyle.Critical, "File Found")
Next
FileSearch(d2, FileName)
Next
Catch excpt As UnauthorizedAccessException
MsgBox(excpt.Message)
End Try
End If
'MsgBox("Done")
End Sub
Aug 15 '06 #1
1 970

Military Smurf wrote:
Okay, so this borrowed code is for doing a recursive file search. The
problem is when I encounter the System Volume Information folder, a special
kind of exception is thrown that ends up terminating the subroutine. I have
two other exceptions that are thrown before the one I described does, yet
they don't terminate the subroutine.

Can anyone tell me why one kind of exception terminates this subroutine,
while another does not?

Sure, the code below is only setup to capture
UnauthorizedAccessException. Any other exception is going to be thrown
right out of the routine... What's the fix? Well, you can either add
another catch statement for the specific exception or you can modify
the code to trap all exceptions by changeing the catch block to read:

Catch excpt As Exception

I caution yout that this is in general not good practice, as it can
cause important exceptions to be ignored... But, it is a possible
solution.
>
Sub FileSearch(ByVal sDir As String, ByVal FileName As String)
Dim Trigger As Integer = 0
Dim d2 As String
Dim f2 As String
If Trigger = 0 Then
Try
For Each d2 In Directory.GetDirectories(sDir)
For Each f2 In Directory.GetFiles(d2, FileName)
MsgBox(f2, MsgBoxStyle.Critical, "File Found")
Next
FileSearch(d2, FileName)
Next
Catch excpt As UnauthorizedAccessException
MsgBox(excpt.Message)
End Try
End If
'MsgBox("Done")
End Sub
--
Tom Shelton [MVP]

Aug 15 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Chris | last post by:
Hi, a strange behaviour when working with exceptions : when I divide and integer by 0 will an exception be thrown. OK but, when I divide a double by 0 is no exception thrown ??? How come ? ...
12
by: Vasco Lohrenscheit | last post by:
Hi, I have a Problem with unmanaged exception. In the debug build it works fine to catch unmanaged c++ exceptions from other dlls with //managed code: try { //the form loads unmanaged dlls...
1
by: Chris | last post by:
Hi, a strange behaviour when working with exceptions : when I divide and integer by 0 will an exception be thrown. OK but, when I divide a double by 0 is no exception thrown ??? How come ? ...
1
by: joseph pattom | last post by:
Hi all i am using <customErrors mode="On" defaultRedirect="ErrorDisplay.aspx"/> in my web.config file and getting redirected to "ErrorDisplay.aspx" in almost all the unhandled exceptions but in...
16
by: BBM | last post by:
This is so bizarre I hesitate to post it, but I need to get this working. My code looks like this... Private Const cmdTestResourcesSel = "SELECT * FROM TResources" & _ " WHERE Scenario =...
1
by: Anonieko | last post by:
Understanding and Using Exceptions (this is a really long post...only read it if you (a) don't know what try/catch is OR (b) actually write catch(Exception ex) or catch{ }) The first thing I...
4
by: Demetri | last post by:
I posted this question about a week or so ago. I never got any replies so please forgive me if you have already read this question. I have the following in my web config file: <customErrors...
0
RedSon
by: RedSon | last post by:
Chapter 3: What are the most common Exceptions and what do they mean? As we saw in the last chapter, there isn't only the standard Exception, but you also get special exceptions like...
3
by: girish574 | last post by:
After the integration of boost serialization code, the exceptions are not at all getting caught in my application. Im building on RHEL4 kernel 2.6.9-42.ELsmp and gcc version is 4.0.2. The...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.