Results 1 to 14 of 14

Thread: Handled Exception

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Handled Exception

    Hi,

    In a parent subroutine with a Try/Catch I want to check if a file is open.
    If the file is open then it seems to create an exception in the ?parent? routine which means that it doesn't continue with the code.
    Is there any way to handle the exception in the subroutine so that it doesn't interfere with the parent?

    And is the a term for a parent subroutine?

    Code:
        Function IsFileOpen(ByRef FileName As String) As Boolean
            Dim blnRetVal As Boolean = False
            Dim fs As FileStream = Nothing
            Try
                fs = File.Open(FileName, FileMode.Open, FileAccess.Read, FileShare.None)
            Catch ex As Exception
                    blnRetVal = True
                Finally
                    If Not IsNothing(fs) Then
                        fs.Close()
                    End If
                End Try
            Return blnRetVal
        End Function
    Last edited by sgrya1; Feb 5th, 2019 at 11:30 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width