Prevetning errors from causing a program to shut down

Discussion in 'Code Snippets and Tutorials' started by the_skip, May 25, 2007.

  1. the_skip

    the_skip Level IV

    Joined:
    Dec 25, 2006
    Messages:
    2,354
    Likes Received:
    1
    Location:
    Indiana
    You know how you hate the debug error often runtime 13 or and out of place array. Well put this at the top of every function/sub you have
    Code (Text):
    1. on error goto errorhandeler
    Then at the bottom of the sub/function put
    Code (Text):
    1.  
    2. exit sub
    3. errorhandeler:
    4.  
    5.             MsgBox (Err.Number & ", " & Err.Description)
    6.    
    7.  
    YOu need the exit sub to make sure that the sud/function goess to the error handeler
     
  2. Pankirk

    Pankirk Level III

    Joined:
    Nov 12, 2006
    Messages:
    652
    Likes Received:
    28
    Location:
    America
    Or, if you dont want anything to popup then just put "on error resume next" and when theres an error, nothing will happen. But I dont reccomend using it, people should use your way instead.
     
  3. ricky92

    ricky92 Administrator
    Staff Member

    Joined:
    Nov 10, 2006
    Messages:
    1,866
    Likes Received:
    67
    If I'm not worng this won't prevent shutting down. You should put "Err.Clear" just after the MsgBox...
     
  4. the_skip

    the_skip Level IV

    Joined:
    Dec 25, 2006
    Messages:
    2,354
    Likes Received:
    1
    Location:
    Indiana
    Nope this prevents shutdown also to esily sopy errors select the window and press ctr+c
    ---------------------------
    MSP
    ---------------------------
    13, Type mismatch
    ---------------------------
    OK
    ---------------------------
     
  5. Billy

    Billy Level IV

    Joined:
    Feb 21, 2007
    Messages:
    1,856
    Likes Received:
    39
    does that mean you can do

    Code (Text):
    1. on error err.clear
    and that would work too?
    [/code]