DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Error handling in VB.net

Hybrid View

  1. #1
    Sachin Guest

    Error handling in VB.net


    Hello all!

    I am preparing a strategy of porting my existing app to VB.NET. Various
    language changes in VB.net are ok to handle except one i.e. error handling
    In every (almost) routine of our project (means aroung 4000+) we have a On
    error goto FnName_ErrHandler and there we do error logging, exiting,
    retrying or resuming on the next line. With the new try...catch way of error
    handling (structured error handling) does anyone have a good idea of how
    i
    can replace my existing error handling functionality??? Has anyone found
    out
    some method.

    I guess that solution cannot be something easy, as earlier one can say
    "Resume next" or "Resume" and does not have to bother on which line the
    error occurs. In my scenario what should i do?? write a try catch for every
    line??? that would be too much....

    Any help will be appreciated...

    Sachin







  2. #2
    Bob Butler Guest

    Re: Error handling in VB.net


    "Sachin" <baroc@vsnl.com> wrote in message news:3ba71e69$1@news.devx.com...
    > I am preparing a strategy of porting my existing app to VB.NET. Various
    > language changes in VB.net are ok to handle except one i.e. error handling
    > In every (almost) routine of our project (means aroung 4000+) we have a On
    > error goto FnName_ErrHandler and there we do error logging, exiting,
    > retrying or resuming on the next line. With the new try...catch way of

    error
    > handling (structured error handling) does anyone have a good idea of how
    > i
    > can replace my existing error handling functionality??? Has anyone found
    > out
    > some method.


    VB.Net still supports the "On Error" handling and for ported code I'd
    probably leave that intact, possibly manually updating specific procedures
    where I thought Try/Catch would be significantly better.



  3. #3
    Kathleen Dollard Guest

    Re: Error handling in VB.net

    Sachin,

    I am on a bit of a crusade to clarify "porting" vs "transitioning". If you
    are porting code using the wizard, then I agree with Bob.

    If you meant transitioning, meaning to me moving your code to VB.Net with a
    good balance between ease of transition and VB.Net high quality code, then I
    would suggest a different answer. The different answer would start with
    when/how you are using Resume/Resume next (I almost never used these except
    during debugging after an Exit Sub). Try/Catch is (IMO) excellent for
    catching predictable failures (file not found, etc). It is also excellent
    for benign errors, although hopefully we will have to handle less of these
    with VB.Net. In both of these cases, handling the error across an individual
    line or small group of lines is appropriate. Combine this with Try/Catch
    that closely resembles your current error handling and I think you have a
    plan. If you have something like

    Function Fred()
    On Error goto ErrorHandler

    ' body of function

    Cleanup:

    ' Cleanup stuff

    Exit Function

    ErrorHandler:

    ' Error handling stuff

    Goto Cleanup

    End Function

    This can be replaced with

    Function Fred
    Try
    ' Body of function
    Catch
    ' Error handling stuff
    Finally
    ' Cleanup stuff
    End Try

    Can you point out ways you are concerned with this fitting your needs?

    --
    Kathleen
    (MS-MVP)
    Reply in the newsgroup so everyone can benefit
    --



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center