Link to home
Start Free TrialLog in
Avatar of VBdotnet2005
VBdotnet2005Flag for United States of America

asked on

using & try catch

Can I use Try Catch inside Using statement to report if errors?

Using ...
      Using...
            try

            Catch
            'to report erro
            End try

            
      End using

End using
Avatar of Jared_S
Jared_S

When declaring a namespace?
Nope. That's an executable statement so it has to be in the body of a procedure.
Avatar of Naman Goel
yes you can.

Actually using block is something like this

Dim resource As New resourceType
Try
    ' Insert code to work with resource.
'here you can add whatever you want including extra try catch block
Finally
    If resource IsNot Nothing Then
        resource.Dispose()
    End If
End Try
Avatar of VBdotnet2005

ASKER

Can I also do this? I want to send any error to myself.



Try
    using con as new sqlconnection..
      'my other code
    end using
      
Catch
    'code to report error
End Try
ASKER CERTIFIED SOLUTION
Avatar of Naman Goel
Naman Goel
Flag of India 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
thank you
Thanks from me as well Narman. I obviously learned something here..