Re: Replacement for Resume Next

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




Michael wrote:
> Hi Everyone,
> I'm using VS 2005 now and would like to know if .Net has a replacement for
> the Resume Next clause. I would like to do something like the following:
> On Error Resume Next
> value = My.Computer.FileSystem.GetDirectories(Path & "\" & tbl.Name )
> if value.Count > 0 then
> My.Computer.FileSystem.CreateDirectory(Path & "\" & tbl.Name)
> end if
> I wanted to see if a Directory existed. But if the main dir is not there,
> GetDirectories throws an exception. In this case is good, indicating that its
> not there. But I need to the code to continue without going to the Catch
> block. Is there a way to do this. Thanks for any info.

You could wrap just this line in a Try Catch block. However, it's a
good idea to avoid using exceptions as error handlers when there are
alternatives. In particular here, do you have a reason to avoid the use
of My.Computer.FileSystem.DirectoryExists?

Dim sTableDirectory As String = Path & "\" & tbl.Name
If Not My.Computer.FileSystem.DirectoryExists(sTableDirectory) Then
My.Computer.FileSystem.CreateDirectory(sTableDirectory)
End If

--
Larry Lard
Replies to group please

.



Relevant Pages

  • Re: using ConcurrentHashMaps
    ... Why did you use if clause and explicitly throw NullPointerException if ... and learning exception handling mechanism. ... The if statement just prevents synchronization in cases where we will ... A good design may just avoid ...
    (comp.lang.java.programmer)
  • Re: Finally in IE
    ... If an exception is thrown, each catch clause is inspected in turn ... the clause executes wether or not an exception is thrown ... Firefox considers your <script> block as self-enclosed system. ...
    (comp.lang.javascript)
  • Re: "ensure" hiding actual error
    ... You caused another exception inside your ensure clause, ... problems with handling correctly the original exception. ... IIRC initially this was about a syntax error. ...
    (comp.lang.ruby)
  • [Proposal] using statement enhancements
    ... Mostly always you use the using clause you deal with native ressources, ... exception handlinjg is sooner or later inevitable. ... Rollback(); ...
    (microsoft.public.dotnet.languages.csharp)