Results 1 to 8 of 8

Thread: error trapping

  1. #1

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075

    error trapping

    I hate to bring up the issue of the Exit Sub Procedure...it seems to be a touchy topic in here...but here goes...

    in a Try, Catch structure will the code always go to Finally? Even if there is an Exit Sub in the Catch portion?

    My question is pertaining to closing a connection?

    thanks
    It's tough being an unhandled exception...

    ___________
    VB.NET 2008
    VB.NET 2010
    ORACLE 11g
    CRYSTAL 11

  2. #2
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    Palermo, Italy
    Posts
    325
    Try it
    VB Code:
    1. Public Sub DivideByZero()
    2.         Dim x As Long
    3.         Dim y As Long = 0
    4.  
    5.         Try
    6.             x = 2 \ y
    7.         Catch eg As Exception
    8.             Exit Sub
    9.         Finally
    10.             MsgBox("Got Finally executed ))")
    11.         End Try
    12. End Function
    Wrote it on the fly...
    Learn, this is the Keyword...

  3. #3

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    if you dont have the exit sub in the catch portion...will the code still run through the rest of the procedure?
    It's tough being an unhandled exception...

    ___________
    VB.NET 2008
    VB.NET 2010
    ORACLE 11g
    CRYSTAL 11

  4. #4
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    Palermo, Italy
    Posts
    325
    If you don't have the Exit Sub statement it will go...
    Learn, this is the Keyword...

  5. #5
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    MSDN
    An "enabled" error handler is one that is turned on by an On Error statement; an "active" error handler is an enabled handler that is in the process of handling an error. If an error occurs while an error handler is active (between the occurrence of the error and a Resume, Exit Sub, Exit Function, or Exit Property statement), the current procedure's error handler can't handle the error.

  6. #6
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    Palermo, Italy
    Posts
    325
    Pirate: What do you mean?
    VB Code:
    1. Public Sub DivideByZero()
    2.         Dim x As Long
    3.         Dim y As Long = 0
    4.  
    5.         Try
    6.             x = 2 \ y
    7.         Catch eg As Exception
    8.             'Here errors can't be handled unless another try statement?
    9.             ' x= 2 \ y    throws an error!!!
    10.         Finally
    11.             MsgBox("Got Finally executed ))")
    12.         End Try
    13. End Function
    Sure is that what you mean...
    Learn, this is the Keyword...

  7. #7
    Fanatic Member VBCrazyCoder's Avatar
    Join Date
    Apr 2003
    Posts
    681
    If you cause an error in your catch block then it will be unhandled unless you have it in its own try block.

  8. #8
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Finally ALWAYS will fire wether you get an error or not, and yes it will fire off before you 'Return'/Exit Sub! (Use Return )
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

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