Link to home
Start Free TrialLog in
Avatar of dwe0608
dwe0608Flag for Australia

asked on

Error Handling in Function vb.net

Hi All ... learning VB.NET as a hobby ...

How can I properly implement an error handling routine in the following function and return true for the process being started and false for an error ...
   ' pass in a fully qualified filename
    Public Function fnShellOpenVB(fn As String)
        Dim p As New System.Diagnostics.Process
        Dim s As New System.Diagnostics.ProcessStartInfo(fn)
        s.UseShellExecute = True
        p.StartInfo = s
        p.Start()
    End Function

Open in new window


MTIA

DWE
Avatar of Shaun Vermaak
Shaun Vermaak
Flag of Australia image

   ' pass in a fully qualified filename
    Public Function fnShellOpenVB(fn As String) As Boolean
        Try
            Dim p As New System.Diagnostics.Process
            Dim s As New System.Diagnostics.ProcessStartInfo(fn)
            s.UseShellExecute = True
            p.StartInfo = s
            p.Start()
            Return true
        Catch
            Return false
        End Try
    End Function

Open in new window

Avatar of dwe0608

ASKER

Hi Shaun,

Thanks for the fast response. So the user has some feedback on the error, would the following work?

    Public Function fnShellOpenVB(fn As String) As Boolean
        Try
            Dim p As New System.Diagnostics.Process
            Dim s As New System.Diagnostics.ProcessStartInfo(fn)
            s.UseShellExecute = True

            p.StartInfo = s
            p.Start()
            fnShellOpenVB = True
        Catch e As Exception
            MsgBox(e.Message + " (" + e.ToString() + ")")
            fnShellOpenVB = False
        End Try

    End Function

Open in new window


MTIA
DWE
ASKER CERTIFIED SOLUTION
Avatar of Shaun Vermaak
Shaun Vermaak
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dwe0608

ASKER

Thanks Shaun ... Great Answer ...