Re: QUERY: 'On Error Resume Next' scope rules

Discussion in 'ASP .Net' started by Kevin Spencer, Jun 17, 2006.

  1. Perhaps the reason you haven't seen any discussion about it here is that
    although the "On Error" statement is included in VB.Net for those who have
    come from a VB6 or VBScript background (I would suppose), it is not
    recommended to use it. ASP and ASP.Net are entirely different technologies.
    ASP is purely procedural; ASP.Net is purely object-oriented. In fact, you
    are the first person I've ever heard of that has used it.

    You might be surprised to learn that the "infamous" try/catch structured
    exception handling is part of the .Net specification, and is supported by
    VB.Net, C#, and every other .Net language (AFAIK). It is far better to use
    try/catch than to use "On Error." You can find it documented here:


    Kevin Spencer
    Microsoft MVP
    Professional Chicken Salad Alchemist

    I recycle.
    I send everything back to the planet it came from.

    "dhruba.bandopadhyay" <>
    wrote in message news:...
    > This has been puzzling me for very long time and no where has
    > talked about the scope of a 'On Error Resume Next' statement.
    > When we program ASP(.NET) pages then we usually like to let
    > ASP(.NET) stop at errors and report back to us. However there
    > are parts of our scripts that we know an error will be thrown
    > and we encapsulate that area inbetween:
    > On Error Resume Next
    > Err.Clear
    > 'Try block
    > If Err.Number Then
    > 'Catch block
    > End If
    > On Error GoTo 0
    > This is similar to the infamous try {} catch(e) {} blocks in
    > Java/C++, etc.
    > If we forget the last line 'On Error GoTo 0' then our ASP(.NET)
    > scripts runs over all errors thrown and we find it hard to
    > find bugs. So the big question is, does 'On Error Resume Next'
    > go out of scope when it's written inside a block
    > (eg. Function)?
    > Function Function1()
    > On Error Resume Next
    > 'Our code
    > End Function
    > When the Function1 call returns, does the outside calling scope
    > automatically stays as it was (On Error GoTo 0)?
    > --
    > dhruba.bandopadhyay
    > ------------------------------------------------------------------------
    > Posted via
    > ------------------------------------------------------------------------
    Kevin Spencer, Jun 17, 2006
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Deniz Bahar
    Andrey Tarasevich
    Mar 9, 2005
  2. Jitu>>

    On Error Resume Next

    Jitu>>, Jul 14, 2003, in forum: ASP General
    Ray at
    Jul 14, 2003
  3. jason

    Avoid On Error Resume Next?

    jason, Aug 14, 2003, in forum: ASP General
    Ray at
    Aug 14, 2003
  4. Laphan

    The truth re On Error Resume Next

    Laphan, Oct 26, 2005, in forum: ASP General
    Bob Barrows [MVP]
    Oct 26, 2005
  5. jay
    Austin Ziegler
    Feb 22, 2007

Share This Page